Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 99.0% → 99.0%
Time: 34.1s
Alternatives: 9
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 9 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} \\ \left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{\frac{\pi}{-s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\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(Float32(-s) * log(Float32(Float32(Float32(1.0) / Float32(Float32(u / Float32(Float32(1.0) + exp(Float32(Float32(pi) / Float32(-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}

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

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

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

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

Alternative 2: 25.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(2, s \cdot u, \mathsf{fma}\left(2, s \cdot \left(u \cdot u\right), 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \log \left(\frac{\pi}{s}\right) \end{array} \]
(FPCore (u s)
 :precision binary32
 (-
  (fma
   2.0
   (* s u)
   (fma 2.0 (* s (* u u)) (* 2.6666666666666665 (* s (pow u 3.0)))))
  (* s (log (/ PI s)))))
float code(float u, float s) {
	return fmaf(2.0f, (s * u), fmaf(2.0f, (s * (u * u)), (2.6666666666666665f * (s * powf(u, 3.0f))))) - (s * logf((((float) M_PI) / s)));
}
function code(u, s)
	return Float32(fma(Float32(2.0), Float32(s * u), fma(Float32(2.0), Float32(s * Float32(u * u)), Float32(Float32(2.6666666666666665) * Float32(s * (u ^ Float32(3.0)))))) - Float32(s * log(Float32(Float32(pi) / s))))
end
\begin{array}{l}

\\
\mathsf{fma}\left(2, s \cdot u, \mathsf{fma}\left(2, s \cdot \left(u \cdot u\right), 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \log \left(\frac{\pi}{s}\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(u \cdot -0.25 + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
    3. distribute-lft-out14.7%

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

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
  8. Step-by-step derivation
    1. expm1-def24.5%

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

      \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)} \]
    3. distribute-lft-neg-in24.7%

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

      \[\leadsto \color{blue}{s \cdot \left(-\log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} \]
    5. associate-/l*24.7%

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

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + -0.5 \cdot u\right)\right)\right) + -1 \cdot \log s\right)} \]
    2. neg-mul-124.7%

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

      \[\leadsto \left(-s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + \color{blue}{u \cdot -0.5}\right)\right)\right) + -1 \cdot \log s\right) \]
    4. mul-1-neg24.7%

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right) + \left(2 \cdot \left(s \cdot u\right) + \left(2 \cdot \left(s \cdot {u}^{2}\right) + 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right)} \]
  14. Step-by-step derivation
    1. +-commutative25.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(s \cdot u\right) + \left(2 \cdot \left(s \cdot {u}^{2}\right) + 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) + -1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right)} \]
    2. mul-1-neg25.0%

      \[\leadsto \left(2 \cdot \left(s \cdot u\right) + \left(2 \cdot \left(s \cdot {u}^{2}\right) + 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) + \color{blue}{\left(-s \cdot \left(\log \pi - \log s\right)\right)} \]
    3. unsub-neg25.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(s \cdot u\right) + \left(2 \cdot \left(s \cdot {u}^{2}\right) + 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \left(\log \pi - \log s\right)} \]
    4. fma-def25.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, s \cdot u, 2 \cdot \left(s \cdot {u}^{2}\right) + 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)} - s \cdot \left(\log \pi - \log s\right) \]
    5. fma-def25.0%

      \[\leadsto \mathsf{fma}\left(2, s \cdot u, \color{blue}{\mathsf{fma}\left(2, s \cdot {u}^{2}, 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)}\right) - s \cdot \left(\log \pi - \log s\right) \]
    6. unpow225.0%

      \[\leadsto \mathsf{fma}\left(2, s \cdot u, \mathsf{fma}\left(2, s \cdot \color{blue}{\left(u \cdot u\right)}, 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \left(\log \pi - \log s\right) \]
    7. log-div25.0%

      \[\leadsto \mathsf{fma}\left(2, s \cdot u, \mathsf{fma}\left(2, s \cdot \left(u \cdot u\right), 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \color{blue}{\log \left(\frac{\pi}{s}\right)} \]
  15. Simplified25.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, s \cdot u, \mathsf{fma}\left(2, s \cdot \left(u \cdot u\right), 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \log \left(\frac{\pi}{s}\right)} \]
  16. Final simplification25.0%

    \[\leadsto \mathsf{fma}\left(2, s \cdot u, \mathsf{fma}\left(2, s \cdot \left(u \cdot u\right), 2.6666666666666665 \cdot \left(s \cdot {u}^{3}\right)\right)\right) - s \cdot \log \left(\frac{\pi}{s}\right) \]

Alternative 3: 25.3% accurate, 1.8× speedup?

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

\\
\mathsf{fma}\left(-1, s \cdot \left(\log \pi - \log s\right), 2 \cdot \left(s \cdot u + s \cdot \left(u \cdot u\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(u \cdot -0.25 + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
    3. distribute-lft-out14.7%

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

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
  8. Step-by-step derivation
    1. expm1-def24.5%

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

      \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)} \]
    3. distribute-lft-neg-in24.7%

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

      \[\leadsto \color{blue}{s \cdot \left(-\log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} \]
    5. associate-/l*24.7%

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

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + -0.5 \cdot u\right)\right)\right) + -1 \cdot \log s\right)} \]
    2. neg-mul-124.7%

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

      \[\leadsto \left(-s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + \color{blue}{u \cdot -0.5}\right)\right)\right) + -1 \cdot \log s\right) \]
    4. mul-1-neg24.7%

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right) + \left(2 \cdot \left(s \cdot u\right) + 2 \cdot \left(s \cdot {u}^{2}\right)\right)} \]
  14. Step-by-step derivation
    1. fma-def25.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, s \cdot \left(\log \pi - \log s\right), 2 \cdot \left(s \cdot u\right) + 2 \cdot \left(s \cdot {u}^{2}\right)\right)} \]
    2. distribute-lft-out25.0%

      \[\leadsto \mathsf{fma}\left(-1, s \cdot \left(\log \pi - \log s\right), \color{blue}{2 \cdot \left(s \cdot u + s \cdot {u}^{2}\right)}\right) \]
    3. unpow225.0%

      \[\leadsto \mathsf{fma}\left(-1, s \cdot \left(\log \pi - \log s\right), 2 \cdot \left(s \cdot u + s \cdot \color{blue}{\left(u \cdot u\right)}\right)\right) \]
  15. Simplified25.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-1, s \cdot \left(\log \pi - \log s\right), 2 \cdot \left(s \cdot u + s \cdot \left(u \cdot u\right)\right)\right)} \]
  16. Final simplification25.0%

    \[\leadsto \mathsf{fma}\left(-1, s \cdot \left(\log \pi - \log s\right), 2 \cdot \left(s \cdot u + s \cdot \left(u \cdot u\right)\right)\right) \]

Alternative 4: 25.2% accurate, 3.4× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(u \cdot -0.25 + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
    3. distribute-lft-out14.7%

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

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
  8. Step-by-step derivation
    1. expm1-def24.5%

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

      \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)} \]
    3. distribute-lft-neg-in24.7%

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

      \[\leadsto \color{blue}{s \cdot \left(-\log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} \]
    5. associate-/l*24.7%

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

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + -0.5 \cdot u\right)\right)\right) + -1 \cdot \log s\right)} \]
    2. neg-mul-124.7%

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

      \[\leadsto \left(-s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + \color{blue}{u \cdot -0.5}\right)\right)\right) + -1 \cdot \log s\right) \]
    4. mul-1-neg24.7%

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right) + \left(2 \cdot \left(s \cdot u\right) + 2 \cdot \left(s \cdot {u}^{2}\right)\right)} \]
  14. Step-by-step derivation
    1. +-commutative25.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(s \cdot u\right) + 2 \cdot \left(s \cdot {u}^{2}\right)\right) + -1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right)} \]
    2. mul-1-neg25.0%

      \[\leadsto \left(2 \cdot \left(s \cdot u\right) + 2 \cdot \left(s \cdot {u}^{2}\right)\right) + \color{blue}{\left(-s \cdot \left(\log \pi - \log s\right)\right)} \]
    3. unsub-neg25.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(s \cdot u\right) + 2 \cdot \left(s \cdot {u}^{2}\right)\right) - s \cdot \left(\log \pi - \log s\right)} \]
    4. distribute-lft-out25.0%

      \[\leadsto \color{blue}{2 \cdot \left(s \cdot u + s \cdot {u}^{2}\right)} - s \cdot \left(\log \pi - \log s\right) \]
    5. unpow225.0%

      \[\leadsto 2 \cdot \left(s \cdot u + s \cdot \color{blue}{\left(u \cdot u\right)}\right) - s \cdot \left(\log \pi - \log s\right) \]
    6. log-div25.0%

      \[\leadsto 2 \cdot \left(s \cdot u + s \cdot \left(u \cdot u\right)\right) - s \cdot \color{blue}{\log \left(\frac{\pi}{s}\right)} \]
  15. Simplified25.0%

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

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

Alternative 5: 25.2% accurate, 3.5× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(u \cdot -0.25 + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
    3. distribute-lft-out14.7%

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

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
  8. Step-by-step derivation
    1. expm1-def24.5%

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

      \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)} \]
    3. distribute-lft-neg-in24.7%

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

      \[\leadsto \color{blue}{s \cdot \left(-\log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} \]
    5. associate-/l*24.7%

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

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + -0.5 \cdot u\right)\right)\right) + -1 \cdot \log s\right)} \]
    2. neg-mul-124.7%

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

      \[\leadsto \left(-s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + \color{blue}{u \cdot -0.5}\right)\right)\right) + -1 \cdot \log s\right) \]
    4. mul-1-neg24.7%

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

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

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

      \[\leadsto \color{blue}{2 \cdot \left(s \cdot u\right) + -1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right)} \]
    2. mul-1-neg24.9%

      \[\leadsto 2 \cdot \left(s \cdot u\right) + \color{blue}{\left(-s \cdot \left(\log \pi - \log s\right)\right)} \]
    3. unsub-neg24.9%

      \[\leadsto \color{blue}{2 \cdot \left(s \cdot u\right) - s \cdot \left(\log \pi - \log s\right)} \]
    4. log-div24.9%

      \[\leadsto 2 \cdot \left(s \cdot u\right) - s \cdot \color{blue}{\log \left(\frac{\pi}{s}\right)} \]
  15. Simplified24.9%

    \[\leadsto \color{blue}{2 \cdot \left(s \cdot u\right) - s \cdot \log \left(\frac{\pi}{s}\right)} \]
  16. Final simplification24.9%

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

Alternative 6: 25.2% accurate, 3.6× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(u \cdot -0.25 + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
    3. distribute-lft-out14.7%

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

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} - 1} \]
  8. Step-by-step derivation
    1. expm1-def24.5%

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

      \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)} \]
    3. distribute-lft-neg-in24.7%

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

      \[\leadsto \color{blue}{s \cdot \left(-\log \left(\mathsf{fma}\left(4, \frac{\pi \cdot \left(\mathsf{fma}\left(u, -0.25, 0.25\right) + u \cdot -0.25\right)}{s}, 1\right)\right)\right)} \]
    5. associate-/l*24.7%

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

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + -0.5 \cdot u\right)\right)\right) + -1 \cdot \log s\right)} \]
    2. neg-mul-124.7%

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

      \[\leadsto \left(-s\right) \cdot \left(\log \left(4 \cdot \left(\pi \cdot \left(0.25 + \color{blue}{u \cdot -0.5}\right)\right)\right) + -1 \cdot \log s\right) \]
    4. mul-1-neg24.7%

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \left(\log \pi - \log s\right)\right)} \]
  14. Step-by-step derivation
    1. mul-1-neg24.9%

      \[\leadsto \color{blue}{-s \cdot \left(\log \pi - \log s\right)} \]
    2. log-div24.9%

      \[\leadsto -s \cdot \color{blue}{\log \left(\frac{\pi}{s}\right)} \]
    3. distribute-rgt-neg-in24.9%

      \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{\pi}{s}\right)\right)} \]
  15. Simplified24.9%

    \[\leadsto \color{blue}{s \cdot \left(-\log \left(\frac{\pi}{s}\right)\right)} \]
  16. Final simplification24.9%

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

Alternative 7: 25.2% accurate, 3.6× speedup?

\[\begin{array}{l} \\ \left(-s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\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(Float32(-s) * log1p(Float32(Float32(pi) / s)))
end
\begin{array}{l}

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \log \left(1 + \frac{\pi}{s}\right)\right)} \]
  7. Step-by-step derivation
    1. log1p-def24.9%

      \[\leadsto -1 \cdot \left(s \cdot \color{blue}{\mathsf{log1p}\left(\frac{\pi}{s}\right)}\right) \]
    2. associate-*r*24.9%

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
    3. neg-mul-124.9%

      \[\leadsto \color{blue}{\left(-s\right)} \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right) \]
  8. Simplified24.9%

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

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

Alternative 8: 11.5% 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 99.0%

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

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

    \[\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+11.1%

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

      \[\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--11.1%

      \[\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. *-commutative11.1%

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

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

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

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

    \[\leadsto \color{blue}{4 \cdot \left(\left(\pi \cdot u\right) \cdot 0.5 + \pi \cdot -0.25\right)} \]
  6. Taylor expanded in u around 0 11.1%

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

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

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

      \[\leadsto 4 \cdot \left(\color{blue}{\left(u \cdot 0.5\right)} \cdot \pi + -0.25 \cdot \pi\right) \]
    4. distribute-rgt-out11.1%

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

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

    \[\leadsto 4 \cdot \color{blue}{\left(\pi \cdot \left(0.5 \cdot u + -0.25\right)\right)} \]
  9. Final simplification11.1%

    \[\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 99.0%

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

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

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

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

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

    \[\leadsto -\pi \]

Reproduce

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