Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 26.4s
Alternatives: 12
Speedup: 1.0×

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 12 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 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.0× speedup?

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

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

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

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

Alternative 2: 97.5% accurate, 1.4× speedup?

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

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

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

    \[\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 inf 97.2%

    \[\leadsto \left(-s\right) \cdot \log \color{blue}{\left(\frac{1}{\left(\frac{1}{1 + e^{-1 \cdot \frac{\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) \cdot u} - 1\right)} \]
  4. Step-by-step derivation
    1. sub-neg97.2%

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

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

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

Alternative 3: 98.9% 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.1%

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

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

    \[\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 4: 25.3% accurate, 1.8× speedup?

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

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

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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) - \log s\right) \]
  7. Simplified24.6%

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

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

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

Alternative 5: 25.3% accurate, 1.8× speedup?

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

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

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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) - \log s\right) \]
  7. Simplified24.6%

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

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

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

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

      \[\leadsto \left(-s\right) \cdot \left(\mathsf{fma}\left(-2, u \cdot u, \log \pi + \color{blue}{u \cdot -2}\right) - \log s\right) \]
  10. Simplified24.9%

    \[\leadsto \left(-s\right) \cdot \left(\color{blue}{\mathsf{fma}\left(-2, u \cdot u, \log \pi + u \cdot -2\right)} - \log s\right) \]
  11. Final simplification24.9%

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

Alternative 6: 25.3% accurate, 2.4× speedup?

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

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

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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) - \log s\right) \]
  7. Simplified24.6%

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

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

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

Alternative 7: 25.3% accurate, 2.4× speedup?

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

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

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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) - \log s\right) \]
  7. Simplified24.6%

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

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

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

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

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

Alternative 8: 25.3% accurate, 2.4× 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 99.1%

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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) - \log s\right) \]
  7. Simplified24.6%

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

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

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

Alternative 9: 25.1% 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.1%

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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) - \log s\right) \]
  7. Simplified24.6%

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

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

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

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

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

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

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

Alternative 10: 25.1% accurate, 3.6× speedup?

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

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

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 11.6% accurate, 6.5× speedup?

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

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

    \[\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. Taylor expanded in s around -inf 24.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(-s\right) \cdot \frac{\color{blue}{\mathsf{fma}\left(u, \pi \cdot -0.5, \pi \cdot 0.25\right)} \cdot 4}{s} \]
    7. associate-/l*11.8%

      \[\leadsto \left(-s\right) \cdot \color{blue}{\frac{\mathsf{fma}\left(u, \pi \cdot -0.5, \pi \cdot 0.25\right)}{\frac{s}{4}}} \]
    8. fma-udef11.8%

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

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

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

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

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

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

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

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

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

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

Alternative 12: 11.4% 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.1%

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

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

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

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

    \[\leadsto \color{blue}{-\pi} \]
  6. Final simplification11.4%

    \[\leadsto -\pi \]

Reproduce

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