Sample trimmed logistic on [-pi, pi]

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

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

Initial Program: 99.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.0% accurate, 1.3× 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(-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}

\\
\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 98.7%

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

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

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

Alternative 2: 25.2% accurate, 4.0× speedup?

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

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

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

    \[\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 \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)}{s}\right)} \]
  5. Taylor expanded in u around 0 24.5%

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

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

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

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

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

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

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

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

      \[\leadsto -1 \cdot \left(s \cdot \left(\color{blue}{\left(-\log \left(\frac{s}{\pi}\right)\right)} + \frac{s}{\pi}\right)\right) \]
  10. Applied egg-rr24.6%

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

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

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

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

    \[\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 \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)}{s}\right)} \]
  5. Taylor expanded in s around 0 24.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-1 \cdot \left(\log \pi - \color{blue}{-1 \cdot \left(-\log s\right)}\right)\right) \]
    10. log-rec24.5%

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

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

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

      \[\leadsto s \cdot \left(-\left(\log \pi - \color{blue}{\left(-\left(-\log s\right)\right)}\right)\right) \]
    14. remove-double-neg24.6%

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

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

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

Alternative 4: 11.5% accurate, 28.9× speedup?

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

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

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

    \[\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 \left(\color{blue}{\left(-0.25 \cdot \left(u \cdot \pi\right) + \left(--0.25\right) \cdot \pi\right)} - 0.25 \cdot \left(u \cdot \pi\right)\right) \]
    3. metadata-eval11.2%

      \[\leadsto -4 \cdot \left(\left(-0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right) \]
    4. 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)} \]
    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. *-commutative11.2%

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

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

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

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

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

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

Alternative 5: 11.5% accurate, 39.4× speedup?

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

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

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

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\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 \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi\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 \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi\right)} \]
    3. distribute-rgt-out--11.2%

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

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

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

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

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

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

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

Alternative 6: 11.5% accurate, 48.1× speedup?

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

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

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

    \[\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 \left(u \cdot \pi\right) + 0.25 \cdot \pi\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 \left(u \cdot \pi\right)\right) - 0.25 \cdot \pi\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 \left(u \cdot \pi\right)\right) + \left(-0.25\right) \cdot \pi\right)} \]
    3. distribute-rgt-out--11.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 11.3% accurate, 61.9× speedup?

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

\\
\frac{-1}{\frac{s}{s \cdot \pi}}
\end{array}
Derivation
  1. Initial program 98.7%

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

    \[\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 \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)}{s}\right)} \]
  5. Taylor expanded in u around 0 24.5%

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \log \left(1 + \frac{\pi}{s}\right)\right)} \]
  6. Taylor expanded in s around inf 10.8%

    \[\leadsto -1 \cdot \left(s \cdot \color{blue}{\frac{\pi}{s}}\right) \]
  7. Step-by-step derivation
    1. associate-*r/10.8%

      \[\leadsto -1 \cdot \color{blue}{\frac{s \cdot \pi}{s}} \]
    2. clear-num10.8%

      \[\leadsto -1 \cdot \color{blue}{\frac{1}{\frac{s}{s \cdot \pi}}} \]
  8. Applied egg-rr10.8%

    \[\leadsto -1 \cdot \color{blue}{\frac{1}{\frac{s}{s \cdot \pi}}} \]
  9. Final simplification10.8%

    \[\leadsto \frac{-1}{\frac{s}{s \cdot \pi}} \]
  10. Add Preprocessing

Alternative 8: 11.3% accurate, 72.2× speedup?

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

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

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

    \[\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 \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)}{s}\right)} \]
  5. Taylor expanded in u around 0 24.5%

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \log \left(1 + \frac{\pi}{s}\right)\right)} \]
  6. Taylor expanded in s around inf 10.8%

    \[\leadsto -1 \cdot \left(s \cdot \color{blue}{\frac{\pi}{s}}\right) \]
  7. Step-by-step derivation
    1. associate-*r/10.8%

      \[\leadsto -1 \cdot \color{blue}{\frac{s \cdot \pi}{s}} \]
  8. Applied egg-rr10.8%

    \[\leadsto -1 \cdot \color{blue}{\frac{s \cdot \pi}{s}} \]
  9. Final simplification10.8%

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

Alternative 9: 11.3% accurate, 216.5× 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.7%

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

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

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

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

    \[\leadsto \color{blue}{-\pi} \]
  7. Final simplification10.8%

    \[\leadsto -\pi \]
  8. Add Preprocessing

Reproduce

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