Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 99.0% → 99.0%
Time: 18.4s
Alternatives: 8
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 8 alternatives:

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

Initial Program: 99.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.0% accurate, 1.4× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

Alternative 2: 25.2% accurate, 1.8× speedup?

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

\\
{\left(\sqrt[3]{s \cdot \log \left(\frac{s}{\pi}\right)}\right)}^{3}
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sqrt[3]{s \cdot \left(\log s - \log \pi\right)} \cdot \sqrt[3]{s \cdot \left(\log s - \log \pi\right)}\right) \cdot \sqrt[3]{s \cdot \left(\log s - \log \pi\right)}} \]
    2. pow325.0%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{s \cdot \left(\log s - \log \pi\right)}\right)}^{3}} \]
    3. diff-log25.0%

      \[\leadsto {\left(\sqrt[3]{s \cdot \color{blue}{\log \left(\frac{s}{\pi}\right)}}\right)}^{3} \]
  10. Applied egg-rr25.0%

    \[\leadsto \color{blue}{{\left(\sqrt[3]{s \cdot \log \left(\frac{s}{\pi}\right)}\right)}^{3}} \]
  11. Final simplification25.0%

    \[\leadsto {\left(\sqrt[3]{s \cdot \log \left(\frac{s}{\pi}\right)}\right)}^{3} \]

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

Alternative 4: 25.2% accurate, 3.6× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{s \cdot \left(\log s - \log \pi\right)} \]
  9. Taylor expanded in s around inf 24.9%

    \[\leadsto \color{blue}{s \cdot \left(-1 \cdot \log \left(\frac{1}{s}\right) - \log \pi\right)} \]
  10. Step-by-step derivation
    1. log-rec25.0%

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

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

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

      \[\leadsto s \cdot \left(\left(-\color{blue}{\left(-\log s\right)}\right) - \log \pi\right) \]
    5. remove-double-neg25.0%

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

      \[\leadsto s \cdot \color{blue}{\log \left(\frac{s}{\pi}\right)} \]
  11. Simplified25.0%

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

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

Alternative 5: 11.5% accurate, 6.8× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 11.3% accurate, 7.2× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

    \[\leadsto -\pi \]

Alternative 7: 8.9% accurate, 146.0× speedup?

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

\\
2 \cdot \left(s \cdot u\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{2 \cdot \left(s \cdot u\right) + s \cdot \left(\log s - \log \pi\right)} \]
  9. Taylor expanded in u around inf 9.2%

    \[\leadsto \color{blue}{2 \cdot \left(s \cdot u\right)} \]
  10. Final simplification9.2%

    \[\leadsto 2 \cdot \left(s \cdot u\right) \]

Alternative 8: 10.4% accurate, 243.3× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

    \[\leadsto s \cdot \left(-\color{blue}{\left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(-4 \cdot \frac{\pi \cdot \left(u \cdot 0.5 + -0.25\right)}{s}\right)\right)} - 1\right)}\right) \]
  7. Taylor expanded in s around inf 10.4%

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

    \[\leadsto s \cdot 0 \]

Reproduce

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