Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 99.0% → 99.0%
Time: 15.5s
Alternatives: 10
Speedup: 1.4×

Specification

?
\[\left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right) \land \left(0 \leq s \land s \leq 1.0651631\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{1 + e^{\frac{\pi}{s}}}\\ \left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - t_0\right) + t_0} - 1\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (/ 1.0 (+ 1.0 (exp (/ PI s))))))
   (*
    (- s)
    (log
     (-
      (/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 (exp (/ (- PI) s)))) t_0)) t_0))
      1.0)))))
float code(float u, float s) {
	float t_0 = 1.0f / (1.0f + expf((((float) M_PI) / s)));
	return -s * logf(((1.0f / ((u * ((1.0f / (1.0f + expf((-((float) M_PI) / s)))) - t_0)) + t_0)) - 1.0f));
}
function code(u, s)
	t_0 = Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) / s))))
	return Float32(Float32(-s) * log(Float32(Float32(Float32(1.0) / Float32(Float32(u * Float32(Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-Float32(pi)) / s)))) - t_0)) + t_0)) - Float32(1.0))))
end
function tmp = code(u, s)
	t_0 = single(1.0) / (single(1.0) + exp((single(pi) / s)));
	tmp = -s * log(((single(1.0) / ((u * ((single(1.0) / (single(1.0) + exp((-single(pi) / s)))) - t_0)) + t_0)) - single(1.0)));
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{1 + e^{\frac{\pi}{s}}}\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - t_0\right) + t_0} - 1\right)
\end{array}
\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 10 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.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{1}{1 + e^{\frac{\pi}{s}}}\\
\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - t_0\right) + t_0} - 1\right)
\end{array}
\end{array}

Alternative 1: 99.0% accurate, 1.4× speedup?

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

\\
s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Final simplification98.9%

    \[\leadsto s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right) \]

Alternative 2: 24.9% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.25 + u \cdot 0.5\\ s \cdot \left(\log \left(t_0 \cdot \left(\pi \cdot 4\right)\right) + \left(\log s + \frac{s \cdot 0.25}{\pi \cdot t_0}\right)\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (+ 0.25 (* u 0.5))))
   (* s (+ (log (* t_0 (* PI 4.0))) (+ (log s) (/ (* s 0.25) (* PI t_0)))))))
float code(float u, float s) {
	float t_0 = 0.25f + (u * 0.5f);
	return s * (logf((t_0 * (((float) M_PI) * 4.0f))) + (logf(s) + ((s * 0.25f) / (((float) M_PI) * t_0))));
}
function code(u, s)
	t_0 = Float32(Float32(0.25) + Float32(u * Float32(0.5)))
	return Float32(s * Float32(log(Float32(t_0 * Float32(Float32(pi) * Float32(4.0)))) + Float32(log(s) + Float32(Float32(s * Float32(0.25)) / Float32(Float32(pi) * t_0)))))
end
function tmp = code(u, s)
	t_0 = single(0.25) + (u * single(0.5));
	tmp = s * (log((t_0 * (single(pi) * single(4.0)))) + (log(s) + ((s * single(0.25)) / (single(pi) * t_0))));
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.25 + u \cdot 0.5\\
s \cdot \left(\log \left(t_0 \cdot \left(\pi \cdot 4\right)\right) + \left(\log s + \frac{s \cdot 0.25}{\pi \cdot t_0}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(1 + -4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(-4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s} + 1\right)}\right) \]
    2. fma-def24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)}\right) \]
    3. associate--r+24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi}}{s}, 1\right)\right)\right) \]
    4. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi}}{s}, 1\right)\right)\right) \]
    5. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    6. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    7. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    8. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi}{s}, 1\right)\right)\right) \]
    9. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}}{s}, 1\right)\right)\right) \]
  5. Simplified24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25}{s}, 1\right)\right)}\right) \]
  6. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5}}{s}, 1\right)\right)\right) \]
    2. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(u \cdot \pi\right)} \cdot 0.5}{s}, 1\right)\right)\right) \]
    3. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(u \cdot \pi\right) \cdot \color{blue}{\left(0.25 - -0.25\right)}}{s}, 1\right)\right)\right) \]
    4. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    5. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    6. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \left(u \cdot \pi\right)\right)}{s}, 1\right)\right)\right) \]
    7. add-sqr-sqrt24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    8. sqrt-unprod24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{\left(0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    9. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(0.25 \cdot 0.25\right) \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    10. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{0.0625} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    11. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot -0.25\right)} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    12. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(-0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    13. sqrt-unprod-0.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{-0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{-0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    14. add-sqr-sqrt25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{-0.25 \cdot \left(u \cdot \pi\right)}\right)}{s}, 1\right)\right)\right) \]
  7. Applied egg-rr25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 - \pi \cdot \left(u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
  8. Step-by-step derivation
    1. distribute-lft-out--25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
    2. *-commutative25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - \color{blue}{0.5 \cdot u}\right)}{s}, 1\right)\right)\right) \]
  9. Simplified25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - 0.5 \cdot u\right)}}{s}, 1\right)\right)\right) \]
  10. Taylor expanded in s around 0 25.1%

    \[\leadsto s \cdot \left(-\color{blue}{\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)}\right) \]
  11. Step-by-step derivation
    1. add-sqr-sqrt-0.0%

      \[\leadsto s \cdot \color{blue}{\left(\sqrt{-\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)} \cdot \sqrt{-\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)}\right)} \]
    2. sqrt-unprod7.6%

      \[\leadsto s \cdot \color{blue}{\sqrt{\left(-\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)\right) \cdot \left(-\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)\right)}} \]
    3. sqr-neg7.6%

      \[\leadsto s \cdot \sqrt{\color{blue}{\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)}} \]
  12. Applied egg-rr25.2%

    \[\leadsto \color{blue}{s \cdot \log \left(\pi \cdot \left(\left(0.25 + 0.5 \cdot u\right) \cdot 4\right)\right) + s \cdot \left(\log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)} \]
  13. Step-by-step derivation
    1. distribute-lft-in25.2%

      \[\leadsto \color{blue}{s \cdot \left(\log \left(\pi \cdot \left(\left(0.25 + 0.5 \cdot u\right) \cdot 4\right)\right) + \left(\log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)} \]
    2. associate-*r*25.2%

      \[\leadsto s \cdot \left(\log \color{blue}{\left(\left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right) \cdot 4\right)} + \left(\log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right) \]
    3. *-commutative25.2%

      \[\leadsto s \cdot \left(\log \left(\color{blue}{\left(\left(0.25 + 0.5 \cdot u\right) \cdot \pi\right)} \cdot 4\right) + \left(\log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right) \]
    4. associate-*l*25.2%

      \[\leadsto s \cdot \left(\log \color{blue}{\left(\left(0.25 + 0.5 \cdot u\right) \cdot \left(\pi \cdot 4\right)\right)} + \left(\log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right) \]
    5. *-commutative25.2%

      \[\leadsto s \cdot \left(\log \left(\left(0.25 + 0.5 \cdot u\right) \cdot \left(\pi \cdot 4\right)\right) + \left(\log s + \color{blue}{\frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)} \cdot 0.25}\right)\right) \]
    6. associate-*l/25.2%

      \[\leadsto s \cdot \left(\log \left(\left(0.25 + 0.5 \cdot u\right) \cdot \left(\pi \cdot 4\right)\right) + \left(\log s + \color{blue}{\frac{s \cdot 0.25}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}}\right)\right) \]
  14. Simplified25.2%

    \[\leadsto \color{blue}{s \cdot \left(\log \left(\left(0.25 + 0.5 \cdot u\right) \cdot \left(\pi \cdot 4\right)\right) + \left(\log s + \frac{s \cdot 0.25}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)} \]
  15. Final simplification25.2%

    \[\leadsto s \cdot \left(\log \left(\left(0.25 + u \cdot 0.5\right) \cdot \left(\pi \cdot 4\right)\right) + \left(\log s + \frac{s \cdot 0.25}{\pi \cdot \left(0.25 + u \cdot 0.5\right)}\right)\right) \]

Alternative 3: 25.3% accurate, 1.7× speedup?

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

\\
s \cdot \left(\left(\log s - 0.25 \cdot \frac{s}{\pi \cdot 0.25}\right) - \log \left(4 \cdot \left(\pi \cdot \left(0.25 + u \cdot 0.5\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(1 + -4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(-4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s} + 1\right)}\right) \]
    2. fma-def24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)}\right) \]
    3. associate--r+24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi}}{s}, 1\right)\right)\right) \]
    4. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi}}{s}, 1\right)\right)\right) \]
    5. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    6. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    7. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    8. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi}{s}, 1\right)\right)\right) \]
    9. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}}{s}, 1\right)\right)\right) \]
  5. Simplified24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25}{s}, 1\right)\right)}\right) \]
  6. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5}}{s}, 1\right)\right)\right) \]
    2. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(u \cdot \pi\right)} \cdot 0.5}{s}, 1\right)\right)\right) \]
    3. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(u \cdot \pi\right) \cdot \color{blue}{\left(0.25 - -0.25\right)}}{s}, 1\right)\right)\right) \]
    4. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    5. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    6. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \left(u \cdot \pi\right)\right)}{s}, 1\right)\right)\right) \]
    7. add-sqr-sqrt24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    8. sqrt-unprod24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{\left(0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    9. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(0.25 \cdot 0.25\right) \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    10. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{0.0625} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    11. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot -0.25\right)} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    12. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(-0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    13. sqrt-unprod-0.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{-0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{-0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    14. add-sqr-sqrt25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{-0.25 \cdot \left(u \cdot \pi\right)}\right)}{s}, 1\right)\right)\right) \]
  7. Applied egg-rr25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 - \pi \cdot \left(u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
  8. Step-by-step derivation
    1. distribute-lft-out--25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
    2. *-commutative25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - \color{blue}{0.5 \cdot u}\right)}{s}, 1\right)\right)\right) \]
  9. Simplified25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - 0.5 \cdot u\right)}}{s}, 1\right)\right)\right) \]
  10. Taylor expanded in s around 0 25.1%

    \[\leadsto s \cdot \left(-\color{blue}{\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)}\right) \]
  11. Taylor expanded in u around 0 25.1%

    \[\leadsto s \cdot \left(-\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\color{blue}{0.25 \cdot \pi}}\right)\right)\right) \]
  12. Final simplification25.1%

    \[\leadsto s \cdot \left(\left(\log s - 0.25 \cdot \frac{s}{\pi \cdot 0.25}\right) - \log \left(4 \cdot \left(\pi \cdot \left(0.25 + u \cdot 0.5\right)\right)\right)\right) \]

Alternative 4: 25.2% accurate, 2.3× speedup?

\[\begin{array}{l} \\ s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}{s}, 1\right)\right)\right) \end{array} \]
(FPCore (u s)
 :precision binary32
 (* s (- (log (fma -4.0 (/ (* PI (- -0.25 (* u 0.5))) s) 1.0)))))
float code(float u, float s) {
	return s * -logf(fmaf(-4.0f, ((((float) M_PI) * (-0.25f - (u * 0.5f))) / s), 1.0f));
}
function code(u, s)
	return Float32(s * Float32(-log(fma(Float32(-4.0), Float32(Float32(Float32(pi) * Float32(Float32(-0.25) - Float32(u * Float32(0.5)))) / s), Float32(1.0)))))
end
\begin{array}{l}

\\
s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}{s}, 1\right)\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(1 + -4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(-4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s} + 1\right)}\right) \]
    2. fma-def24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)}\right) \]
    3. associate--r+24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi}}{s}, 1\right)\right)\right) \]
    4. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi}}{s}, 1\right)\right)\right) \]
    5. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    6. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    7. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    8. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi}{s}, 1\right)\right)\right) \]
    9. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}}{s}, 1\right)\right)\right) \]
  5. Simplified24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25}{s}, 1\right)\right)}\right) \]
  6. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5}}{s}, 1\right)\right)\right) \]
    2. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(u \cdot \pi\right)} \cdot 0.5}{s}, 1\right)\right)\right) \]
    3. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(u \cdot \pi\right) \cdot \color{blue}{\left(0.25 - -0.25\right)}}{s}, 1\right)\right)\right) \]
    4. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    5. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    6. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \left(u \cdot \pi\right)\right)}{s}, 1\right)\right)\right) \]
    7. add-sqr-sqrt24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    8. sqrt-unprod24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{\left(0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    9. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(0.25 \cdot 0.25\right) \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    10. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{0.0625} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    11. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot -0.25\right)} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    12. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(-0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    13. sqrt-unprod-0.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{-0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{-0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    14. add-sqr-sqrt25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{-0.25 \cdot \left(u \cdot \pi\right)}\right)}{s}, 1\right)\right)\right) \]
  7. Applied egg-rr25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 - \pi \cdot \left(u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
  8. Step-by-step derivation
    1. distribute-lft-out--25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
    2. *-commutative25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - \color{blue}{0.5 \cdot u}\right)}{s}, 1\right)\right)\right) \]
  9. Simplified25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - 0.5 \cdot u\right)}}{s}, 1\right)\right)\right) \]
  10. Final simplification25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}{s}, 1\right)\right)\right) \]

Alternative 5: 25.2% accurate, 3.5× speedup?

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

\\
s \cdot \left(-\log \left(1 + \frac{\pi}{s}\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(1 + -4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(-4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s} + 1\right)}\right) \]
    2. fma-def24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)}\right) \]
    3. associate--r+24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi}}{s}, 1\right)\right)\right) \]
    4. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi}}{s}, 1\right)\right)\right) \]
    5. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    6. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    7. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    8. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi}{s}, 1\right)\right)\right) \]
    9. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}}{s}, 1\right)\right)\right) \]
  5. Simplified24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25}{s}, 1\right)\right)}\right) \]
  6. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5}}{s}, 1\right)\right)\right) \]
    2. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(u \cdot \pi\right)} \cdot 0.5}{s}, 1\right)\right)\right) \]
    3. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(u \cdot \pi\right) \cdot \color{blue}{\left(0.25 - -0.25\right)}}{s}, 1\right)\right)\right) \]
    4. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    5. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    6. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \left(u \cdot \pi\right)\right)}{s}, 1\right)\right)\right) \]
    7. add-sqr-sqrt24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    8. sqrt-unprod24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{\left(0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    9. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(0.25 \cdot 0.25\right) \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    10. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{0.0625} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    11. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot -0.25\right)} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    12. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(-0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    13. sqrt-unprod-0.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{-0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{-0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    14. add-sqr-sqrt25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{-0.25 \cdot \left(u \cdot \pi\right)}\right)}{s}, 1\right)\right)\right) \]
  7. Applied egg-rr25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 - \pi \cdot \left(u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
  8. Step-by-step derivation
    1. distribute-lft-out--25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
    2. *-commutative25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - \color{blue}{0.5 \cdot u}\right)}{s}, 1\right)\right)\right) \]
  9. Simplified25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - 0.5 \cdot u\right)}}{s}, 1\right)\right)\right) \]
  10. Taylor expanded in u around 0 25.0%

    \[\leadsto s \cdot \left(-\color{blue}{\log \left(1 + \frac{\pi}{s}\right)}\right) \]
  11. Final simplification25.0%

    \[\leadsto s \cdot \left(-\log \left(1 + \frac{\pi}{s}\right)\right) \]

Alternative 6: 25.2% accurate, 3.6× speedup?

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

\\
s \cdot \left(-\mathsf{log1p}\left(\frac{\pi}{s}\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(1 + -4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(-4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s} + 1\right)}\right) \]
    2. fma-def24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)}\right) \]
    3. associate--r+24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi}}{s}, 1\right)\right)\right) \]
    4. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi}}{s}, 1\right)\right)\right) \]
    5. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    6. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    7. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    8. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi}{s}, 1\right)\right)\right) \]
    9. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}}{s}, 1\right)\right)\right) \]
  5. Simplified24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25}{s}, 1\right)\right)}\right) \]
  6. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5}}{s}, 1\right)\right)\right) \]
    2. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(u \cdot \pi\right)} \cdot 0.5}{s}, 1\right)\right)\right) \]
    3. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(u \cdot \pi\right) \cdot \color{blue}{\left(0.25 - -0.25\right)}}{s}, 1\right)\right)\right) \]
    4. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    5. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    6. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \left(u \cdot \pi\right)\right)}{s}, 1\right)\right)\right) \]
    7. add-sqr-sqrt24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    8. sqrt-unprod24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{\left(0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    9. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(0.25 \cdot 0.25\right) \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    10. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{0.0625} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    11. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot -0.25\right)} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    12. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(-0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    13. sqrt-unprod-0.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{-0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{-0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    14. add-sqr-sqrt25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{-0.25 \cdot \left(u \cdot \pi\right)}\right)}{s}, 1\right)\right)\right) \]
  7. Applied egg-rr25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 - \pi \cdot \left(u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
  8. Step-by-step derivation
    1. distribute-lft-out--25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
    2. *-commutative25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - \color{blue}{0.5 \cdot u}\right)}{s}, 1\right)\right)\right) \]
  9. Simplified25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - 0.5 \cdot u\right)}}{s}, 1\right)\right)\right) \]
  10. Taylor expanded in u around 0 25.0%

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \log \left(1 + \frac{\pi}{s}\right)\right)} \]
  11. Step-by-step derivation
    1. associate-*r*25.0%

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \log \left(1 + \frac{\pi}{s}\right)} \]
    2. neg-mul-125.0%

      \[\leadsto \color{blue}{\left(-s\right)} \cdot \log \left(1 + \frac{\pi}{s}\right) \]
    3. log1p-def25.0%

      \[\leadsto \left(-s\right) \cdot \color{blue}{\mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  12. Simplified25.0%

    \[\leadsto \color{blue}{\left(-s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  13. Final simplification25.0%

    \[\leadsto s \cdot \left(-\mathsf{log1p}\left(\frac{\pi}{s}\right)\right) \]

Alternative 7: 12.8% accurate, 6.5× speedup?

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

\\
s \cdot \frac{0.25 \cdot \left(-s\right)}{\pi \cdot \left(0.25 + u \cdot 0.5\right)}
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(1 + -4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(-4 \cdot \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s} + 1\right)}\right) \]
    2. fma-def24.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)}\right) \]
    3. associate--r+24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi}}{s}, 1\right)\right)\right) \]
    4. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi}}{s}, 1\right)\right)\right) \]
    5. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    6. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    7. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi}{s}, 1\right)\right)\right) \]
    8. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi}{s}, 1\right)\right)\right) \]
    9. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}}{s}, 1\right)\right)\right) \]
  5. Simplified24.9%

    \[\leadsto s \cdot \left(-\log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25}{s}, 1\right)\right)}\right) \]
  6. Step-by-step derivation
    1. +-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5}}{s}, 1\right)\right)\right) \]
    2. *-commutative24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(u \cdot \pi\right)} \cdot 0.5}{s}, 1\right)\right)\right) \]
    3. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(u \cdot \pi\right) \cdot \color{blue}{\left(0.25 - -0.25\right)}}{s}, 1\right)\right)\right) \]
    4. distribute-rgt-out--24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    5. cancel-sign-sub-inv24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \color{blue}{\left(0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \left(u \cdot \pi\right)\right)}}{s}, 1\right)\right)\right) \]
    6. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \left(u \cdot \pi\right)\right)}{s}, 1\right)\right)\right) \]
    7. add-sqr-sqrt24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    8. sqrt-unprod24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{\left(0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    9. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(0.25 \cdot 0.25\right) \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    10. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{0.0625} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    11. metadata-eval24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot -0.25\right)} \cdot \left(\left(u \cdot \pi\right) \cdot \left(u \cdot \pi\right)\right)}\right)}{s}, 1\right)\right)\right) \]
    12. swap-sqr24.9%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \sqrt{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right)\right) \cdot \left(-0.25 \cdot \left(u \cdot \pi\right)\right)}}\right)}{s}, 1\right)\right)\right) \]
    13. sqrt-unprod-0.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{\sqrt{-0.25 \cdot \left(u \cdot \pi\right)} \cdot \sqrt{-0.25 \cdot \left(u \cdot \pi\right)}}\right)}{s}, 1\right)\right)\right) \]
    14. add-sqr-sqrt25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot -0.25 + \left(0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{-0.25 \cdot \left(u \cdot \pi\right)}\right)}{s}, 1\right)\right)\right) \]
  7. Applied egg-rr25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot -0.25 - \pi \cdot \left(u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
  8. Step-by-step derivation
    1. distribute-lft-out--25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - u \cdot 0.5\right)}}{s}, 1\right)\right)\right) \]
    2. *-commutative25.0%

      \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\pi \cdot \left(-0.25 - \color{blue}{0.5 \cdot u}\right)}{s}, 1\right)\right)\right) \]
  9. Simplified25.0%

    \[\leadsto s \cdot \left(-\log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\pi \cdot \left(-0.25 - 0.5 \cdot u\right)}}{s}, 1\right)\right)\right) \]
  10. Taylor expanded in s around 0 25.1%

    \[\leadsto s \cdot \left(-\color{blue}{\left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + 0.5 \cdot u\right)\right)\right) + \left(-1 \cdot \log s + 0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}\right)\right)}\right) \]
  11. Taylor expanded in s around inf 12.6%

    \[\leadsto s \cdot \left(-\color{blue}{0.25 \cdot \frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}}\right) \]
  12. Step-by-step derivation
    1. *-commutative12.6%

      \[\leadsto s \cdot \left(-\color{blue}{\frac{s}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)} \cdot 0.25}\right) \]
    2. associate-*l/12.6%

      \[\leadsto s \cdot \left(-\color{blue}{\frac{s \cdot 0.25}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}}\right) \]
  13. Simplified12.6%

    \[\leadsto s \cdot \left(-\color{blue}{\frac{s \cdot 0.25}{\pi \cdot \left(0.25 + 0.5 \cdot u\right)}}\right) \]
  14. Final simplification12.6%

    \[\leadsto s \cdot \frac{0.25 \cdot \left(-s\right)}{\pi \cdot \left(0.25 + u \cdot 0.5\right)} \]

Alternative 8: 11.6% accurate, 6.8× speedup?

\[\begin{array}{l} \\ 4 \cdot \left(\pi \cdot \left(u \cdot 0.5 + -0.25\right)\right) \end{array} \]
(FPCore (u s) :precision binary32 (* 4.0 (* PI (+ (* u 0.5) -0.25))))
float code(float u, float s) {
	return 4.0f * (((float) M_PI) * ((u * 0.5f) + -0.25f));
}
function code(u, s)
	return Float32(Float32(4.0) * Float32(Float32(pi) * Float32(Float32(u * Float32(0.5)) + Float32(-0.25))))
end
function tmp = code(u, s)
	tmp = single(4.0) * (single(pi) * ((u * single(0.5)) + single(-0.25)));
end
\begin{array}{l}

\\
4 \cdot \left(\pi \cdot \left(u \cdot 0.5 + -0.25\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 10.7%

    \[\leadsto \color{blue}{4 \cdot \left(0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)\right)} \]
  4. Step-by-step derivation
    1. associate--r+10.7%

      \[\leadsto 4 \cdot \color{blue}{\left(\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi\right)} \]
    2. cancel-sign-sub-inv10.7%

      \[\leadsto 4 \cdot \color{blue}{\left(\left(0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi\right)} \]
    3. distribute-rgt-out--10.7%

      \[\leadsto 4 \cdot \left(\color{blue}{\left(u \cdot \pi\right) \cdot \left(0.25 - -0.25\right)} + \left(-0.25\right) \cdot \pi\right) \]
    4. *-commutative10.7%

      \[\leadsto 4 \cdot \left(\color{blue}{\left(\pi \cdot u\right)} \cdot \left(0.25 - -0.25\right) + \left(-0.25\right) \cdot \pi\right) \]
    5. metadata-eval10.7%

      \[\leadsto 4 \cdot \left(\left(\pi \cdot u\right) \cdot \color{blue}{0.5} + \left(-0.25\right) \cdot \pi\right) \]
    6. metadata-eval10.7%

      \[\leadsto 4 \cdot \left(\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{-0.25} \cdot \pi\right) \]
    7. *-commutative10.7%

      \[\leadsto 4 \cdot \left(\left(\pi \cdot u\right) \cdot 0.5 + \color{blue}{\pi \cdot -0.25}\right) \]
  5. Simplified10.7%

    \[\leadsto \color{blue}{4 \cdot \left(\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25\right)} \]
  6. Step-by-step derivation
    1. +-commutative10.7%

      \[\leadsto 4 \cdot \color{blue}{\left(\pi \cdot -0.25 + \left(\pi \cdot u\right) \cdot 0.5\right)} \]
    2. associate-*l*10.7%

      \[\leadsto 4 \cdot \left(\pi \cdot -0.25 + \color{blue}{\pi \cdot \left(u \cdot 0.5\right)}\right) \]
    3. distribute-lft-out10.7%

      \[\leadsto 4 \cdot \color{blue}{\left(\pi \cdot \left(-0.25 + u \cdot 0.5\right)\right)} \]
  7. Applied egg-rr10.7%

    \[\leadsto 4 \cdot \color{blue}{\left(\pi \cdot \left(-0.25 + u \cdot 0.5\right)\right)} \]
  8. Final simplification10.7%

    \[\leadsto 4 \cdot \left(\pi \cdot \left(u \cdot 0.5 + -0.25\right)\right) \]

Alternative 9: 11.3% accurate, 7.2× speedup?

\[\begin{array}{l} \\ -\pi \end{array} \]
(FPCore (u s) :precision binary32 (- PI))
float code(float u, float s) {
	return -((float) M_PI);
}
function code(u, s)
	return Float32(-Float32(pi))
end
function tmp = code(u, s)
	tmp = -single(pi);
end
\begin{array}{l}

\\
-\pi
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in u around 0 10.5%

    \[\leadsto \color{blue}{-1 \cdot \pi} \]
  4. Step-by-step derivation
    1. mul-1-neg10.5%

      \[\leadsto \color{blue}{-\pi} \]
  5. Simplified10.5%

    \[\leadsto \color{blue}{-\pi} \]
  6. Final simplification10.5%

    \[\leadsto -\pi \]

Alternative 10: 10.3% accurate, 243.3× speedup?

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

\\
s \cdot 0
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Simplified98.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\right)} \]
  3. Taylor expanded in s around inf 10.5%

    \[\leadsto s \cdot \left(-\log \color{blue}{1}\right) \]
  4. Final simplification10.5%

    \[\leadsto s \cdot 0 \]

Reproduce

?
herbie shell --seed 2023301 
(FPCore (u s)
  :name "Sample trimmed logistic on [-pi, pi]"
  :precision binary32
  :pre (and (and (<= 2.328306437e-10 u) (<= u 1.0)) (and (<= 0.0 s) (<= s 1.0651631)))
  (* (- s) (log (- (/ 1.0 (+ (* u (- (/ 1.0 (+ 1.0 (exp (/ (- PI) s)))) (/ 1.0 (+ 1.0 (exp (/ PI s)))))) (/ 1.0 (+ 1.0 (exp (/ PI s)))))) 1.0))))