Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 16.4s
Alternatives: 13
Speedup: N/A×

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 13 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: 98.9% 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: 98.9% accurate, 1.3× 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.8%

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

    \[\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. Add Preprocessing
  4. Final simplification98.8%

    \[\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) \]
  5. Add Preprocessing

Alternative 2: 25.2% accurate, 2.1× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Taylor expanded in u around 0 24.6%

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

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

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

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

    \[\leadsto \color{blue}{\left(-s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  10. Taylor expanded in s around 0 24.7%

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

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

      \[\leadsto s \cdot \left(-1 \cdot \frac{s}{\pi} + \color{blue}{\left(-\left(\log \pi + -1 \cdot \log s\right)\right)}\right) \]
    3. unsub-neg24.7%

      \[\leadsto s \cdot \color{blue}{\left(-1 \cdot \frac{s}{\pi} - \left(\log \pi + -1 \cdot \log s\right)\right)} \]
    4. associate-*r/24.7%

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

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

      \[\leadsto s \cdot \left(\frac{-s}{\pi} - \left(\log \pi + \color{blue}{\left(-\log s\right)}\right)\right) \]
    7. unsub-neg24.7%

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

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

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

Alternative 3: 25.1% accurate, 2.1× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Taylor expanded in u around 0 24.6%

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

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

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

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

    \[\leadsto \color{blue}{\left(-s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  10. Taylor expanded in s around 0 24.7%

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

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

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

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

      \[\leadsto \left(\log \pi + \color{blue}{\left(-\log s\right)}\right) \cdot \left(-s\right) \]
    5. unsub-neg24.7%

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

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

    \[\leadsto s \cdot \left(\log s - \log \pi\right) \]
  14. Add Preprocessing

Alternative 4: 25.0% accurate, 3.6× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Taylor expanded in u around 0 24.6%

    \[\leadsto \left(-s\right) \cdot \color{blue}{\left(\log \left(1 + \frac{\pi}{s}\right) + -2 \cdot \frac{u \cdot \pi}{s \cdot \left(1 + \frac{\pi}{s}\right)}\right)} \]
  8. Step-by-step derivation
    1. log1p-define24.6%

      \[\leadsto \left(-s\right) \cdot \left(\color{blue}{\mathsf{log1p}\left(\frac{\pi}{s}\right)} + -2 \cdot \frac{u \cdot \pi}{s \cdot \left(1 + \frac{\pi}{s}\right)}\right) \]
    2. associate-/l*24.6%

      \[\leadsto \left(-s\right) \cdot \left(\mathsf{log1p}\left(\frac{\pi}{s}\right) + -2 \cdot \color{blue}{\left(u \cdot \frac{\pi}{s \cdot \left(1 + \frac{\pi}{s}\right)}\right)}\right) \]
  9. Simplified24.6%

    \[\leadsto \left(-s\right) \cdot \color{blue}{\left(\mathsf{log1p}\left(\frac{\pi}{s}\right) + -2 \cdot \left(u \cdot \frac{\pi}{s \cdot \left(1 + \frac{\pi}{s}\right)}\right)\right)} \]
  10. Final simplification24.6%

    \[\leadsto s \cdot \left(-2 \cdot \left(u \cdot \frac{\pi}{s \cdot \left(-1 - \frac{\pi}{s}\right)}\right) - \mathsf{log1p}\left(\frac{\pi}{s}\right)\right) \]
  11. Add Preprocessing

Alternative 5: 25.0% accurate, 3.7× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Taylor expanded in u around 0 24.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{2 \cdot \left(u \cdot \pi\right)}{1 + \frac{\pi}{s}}} - s \cdot \log \left(1 + \frac{\pi}{s}\right) \]
    5. *-commutative24.6%

      \[\leadsto \frac{\color{blue}{\left(u \cdot \pi\right) \cdot 2}}{1 + \frac{\pi}{s}} - s \cdot \log \left(1 + \frac{\pi}{s}\right) \]
    6. *-commutative24.6%

      \[\leadsto \frac{\color{blue}{\left(\pi \cdot u\right)} \cdot 2}{1 + \frac{\pi}{s}} - s \cdot \log \left(1 + \frac{\pi}{s}\right) \]
    7. log1p-define24.6%

      \[\leadsto \frac{\left(\pi \cdot u\right) \cdot 2}{1 + \frac{\pi}{s}} - s \cdot \color{blue}{\mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  9. Simplified24.6%

    \[\leadsto \color{blue}{\frac{\left(\pi \cdot u\right) \cdot 2}{1 + \frac{\pi}{s}} - s \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  10. Final simplification24.6%

    \[\leadsto \frac{2 \cdot \left(u \cdot \pi\right)}{1 + \frac{\pi}{s}} - s \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right) \]
  11. Add Preprocessing

Alternative 6: 25.0% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(1 + \frac{\pi}{s}\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(Float32(-s) * 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}

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Taylor expanded in u around 0 24.6%

    \[\leadsto \left(-s\right) \cdot \color{blue}{\log \left(1 + \frac{\pi}{s}\right)} \]
  8. Add Preprocessing

Alternative 7: 25.0% accurate, 4.1× 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.8%

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Taylor expanded in u around 0 24.6%

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

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

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

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

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

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

Alternative 8: 11.7% accurate, 22.8× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around -inf 11.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto -4 \cdot \left(\pi \cdot \left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.25 \cdot u\right)\right)} + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
    2. expm1-undefine11.2%

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

      \[\leadsto -4 \cdot \left(\pi \cdot \left(\left(e^{\mathsf{log1p}\left(\color{blue}{u \cdot -0.25}\right)} - 1\right) + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
  8. Applied egg-rr11.2%

    \[\leadsto -4 \cdot \left(\pi \cdot \left(\color{blue}{\left(e^{\mathsf{log1p}\left(u \cdot -0.25\right)} - 1\right)} + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
  9. Step-by-step derivation
    1. sub-neg11.2%

      \[\leadsto -4 \cdot \left(\pi \cdot \left(\color{blue}{\left(e^{\mathsf{log1p}\left(u \cdot -0.25\right)} + \left(-1\right)\right)} + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
    2. log1p-undefine11.2%

      \[\leadsto -4 \cdot \left(\pi \cdot \left(\left(e^{\color{blue}{\log \left(1 + u \cdot -0.25\right)}} + \left(-1\right)\right) + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
    3. rem-exp-log11.2%

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

      \[\leadsto -4 \cdot \left(\pi \cdot \left(\left(\left(1 + u \cdot -0.25\right) + \color{blue}{-1}\right) + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
  10. Applied egg-rr11.2%

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

    \[\leadsto -4 \cdot \left(\pi \cdot \left(\left(-1 + \left(1 + u \cdot -0.25\right)\right) + 0.25\right) + \pi \cdot \left(u \cdot -0.25\right)\right) \]
  12. Add Preprocessing

Alternative 9: 11.7% accurate, 28.9× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Step-by-step derivation
    1. expm1-log1p-u23.8%

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

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

      \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \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)} - 1 \]
    4. fma-define13.7%

      \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\mathsf{fma}\left(\pi, -0.25, \left(\pi \cdot u\right) \cdot 0.5\right)}}{s}, 1\right)\right)\right)} - 1 \]
    5. associate-*l*13.7%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\mathsf{fma}\left(\pi, -0.25, \pi \cdot \left(u \cdot 0.5\right)\right)}{s}, 1\right)\right)\right)} - 1} \]
  9. Step-by-step derivation
    1. sub-neg13.7%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\mathsf{fma}\left(\pi, -0.25, \pi \cdot \left(u \cdot 0.5\right)\right)}{s}, 1\right)\right)\right)}} + \left(-1\right) \]
    3. rem-exp-log14.0%

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

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

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

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

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

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

    \[\leadsto -1 + \left(1 - -4 \cdot \left(\pi \cdot -0.25 + 0.5 \cdot \left(u \cdot \pi\right)\right)\right) \]
  13. Add Preprocessing

Alternative 10: 14.2% accurate, 39.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;s \leq 1.0999999780167719 \cdot 10^{-18}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;s \cdot \frac{-\pi}{s}\\ \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (if (<= s 1.0999999780167719e-18) 0.0 (* s (/ (- PI) s))))
float code(float u, float s) {
	float tmp;
	if (s <= 1.0999999780167719e-18f) {
		tmp = 0.0f;
	} else {
		tmp = s * (-((float) M_PI) / s);
	}
	return tmp;
}
function code(u, s)
	tmp = Float32(0.0)
	if (s <= Float32(1.0999999780167719e-18))
		tmp = Float32(0.0);
	else
		tmp = Float32(s * Float32(Float32(-Float32(pi)) / s));
	end
	return tmp
end
function tmp_2 = code(u, s)
	tmp = single(0.0);
	if (s <= single(1.0999999780167719e-18))
		tmp = single(0.0);
	else
		tmp = s * (-single(pi) / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;s \leq 1.0999999780167719 \cdot 10^{-18}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;s \cdot \frac{-\pi}{s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 1.09999998e-18

    1. Initial program 98.8%

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

      \[\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. Add Preprocessing
    4. Taylor expanded in s around inf 22.0%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
    5. Step-by-step derivation
      1. +-commutative22.0%

        \[\leadsto \left(-s\right) \cdot \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)} \]
      2. fma-define22.0%

        \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
    6. Simplified22.0%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    7. Step-by-step derivation
      1. expm1-log1p-u21.9%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \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)} - 1 \]
      4. fma-define11.9%

        \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\mathsf{fma}\left(\pi, -0.25, \left(\pi \cdot u\right) \cdot 0.5\right)}}{s}, 1\right)\right)\right)} - 1 \]
      5. associate-*l*11.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1} + -1 \]
    12. Step-by-step derivation
      1. metadata-eval13.3%

        \[\leadsto \color{blue}{0} \]
    13. Applied egg-rr13.3%

      \[\leadsto \color{blue}{0} \]

    if 1.09999998e-18 < s

    1. Initial program 98.8%

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

      \[\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. Add Preprocessing
    4. Taylor expanded in u around 0 15.1%

      \[\leadsto \left(-s\right) \cdot \color{blue}{\frac{\pi}{s}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 1.0999999780167719 \cdot 10^{-18}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;s \cdot \frac{-\pi}{s}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 14.2% accurate, 61.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;s \leq 1.0999999780167719 \cdot 10^{-18}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-\pi\\ \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (if (<= s 1.0999999780167719e-18) 0.0 (- PI)))
float code(float u, float s) {
	float tmp;
	if (s <= 1.0999999780167719e-18f) {
		tmp = 0.0f;
	} else {
		tmp = -((float) M_PI);
	}
	return tmp;
}
function code(u, s)
	tmp = Float32(0.0)
	if (s <= Float32(1.0999999780167719e-18))
		tmp = Float32(0.0);
	else
		tmp = Float32(-Float32(pi));
	end
	return tmp
end
function tmp_2 = code(u, s)
	tmp = single(0.0);
	if (s <= single(1.0999999780167719e-18))
		tmp = single(0.0);
	else
		tmp = -single(pi);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;s \leq 1.0999999780167719 \cdot 10^{-18}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;-\pi\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 1.09999998e-18

    1. Initial program 98.8%

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

      \[\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. Add Preprocessing
    4. Taylor expanded in s around inf 22.0%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
    5. Step-by-step derivation
      1. +-commutative22.0%

        \[\leadsto \left(-s\right) \cdot \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)} \]
      2. fma-define22.0%

        \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
    6. Simplified22.0%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    7. Step-by-step derivation
      1. expm1-log1p-u21.9%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \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)} - 1 \]
      4. fma-define11.9%

        \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\mathsf{fma}\left(\pi, -0.25, \left(\pi \cdot u\right) \cdot 0.5\right)}}{s}, 1\right)\right)\right)} - 1 \]
      5. associate-*l*11.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1} + -1 \]
    12. Step-by-step derivation
      1. metadata-eval13.3%

        \[\leadsto \color{blue}{0} \]
    13. Applied egg-rr13.3%

      \[\leadsto \color{blue}{0} \]

    if 1.09999998e-18 < s

    1. Initial program 98.8%

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

      \[\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. Add Preprocessing
    4. Taylor expanded in u around 0 15.1%

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

        \[\leadsto \color{blue}{-\pi} \]
    6. Simplified15.1%

      \[\leadsto \color{blue}{-\pi} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 11.7% accurate, 61.9× speedup?

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

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

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around -inf 11.2%

    \[\leadsto \left(-s\right) \cdot \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}\right)} \]
  5. Step-by-step derivation
    1. associate--r+11.2%

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

      \[\leadsto \left(-s\right) \cdot \left(4 \cdot \frac{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \pi\right) + \left(-0.25\right) \cdot \left(u \cdot \pi\right)}}{s}\right) \]
    3. cancel-sign-sub-inv11.2%

      \[\leadsto \left(-s\right) \cdot \left(4 \cdot \frac{\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \pi\right)} + \left(-0.25\right) \cdot \left(u \cdot \pi\right)}{s}\right) \]
    4. metadata-eval11.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot u\right) \cdot \pi} - \pi \]
  10. Simplified11.2%

    \[\leadsto \color{blue}{\left(2 \cdot u\right) \cdot \pi - \pi} \]
  11. Final simplification11.2%

    \[\leadsto \pi \cdot \left(u \cdot 2\right) - \pi \]
  12. Add Preprocessing

Alternative 13: 10.3% accurate, 433.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\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. Add Preprocessing
  4. Taylor expanded in s around inf 24.1%

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}\right)} \]
  5. Step-by-step derivation
    1. +-commutative24.1%

      \[\leadsto \left(-s\right) \cdot \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)} \]
    2. fma-define24.1%

      \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}{s}, 1\right)\right)} \]
  6. Simplified24.1%

    \[\leadsto \left(-s\right) \cdot \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)} \]
  7. Step-by-step derivation
    1. expm1-log1p-u23.8%

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

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

      \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \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)} - 1 \]
    4. fma-define13.7%

      \[\leadsto e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\color{blue}{\mathsf{fma}\left(\pi, -0.25, \left(\pi \cdot u\right) \cdot 0.5\right)}}{s}, 1\right)\right)\right)} - 1 \]
    5. associate-*l*13.7%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\mathsf{fma}\left(\pi, -0.25, \pi \cdot \left(u \cdot 0.5\right)\right)}{s}, 1\right)\right)\right)} - 1} \]
  9. Step-by-step derivation
    1. sub-neg13.7%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \left(-s\right) \cdot \log \left(\mathsf{fma}\left(-4, \frac{\mathsf{fma}\left(\pi, -0.25, \pi \cdot \left(u \cdot 0.5\right)\right)}{s}, 1\right)\right)\right)}} + \left(-1\right) \]
    3. rem-exp-log14.0%

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

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

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

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

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

    \[\leadsto \color{blue}{1} + -1 \]
  12. Step-by-step derivation
    1. metadata-eval10.7%

      \[\leadsto \color{blue}{0} \]
  13. Applied egg-rr10.7%

    \[\leadsto \color{blue}{0} \]
  14. Add Preprocessing

Reproduce

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