Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 20.7s
Alternatives: 10
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 10 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, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{\pi}{s}}\\
t_1 := \mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{1}{-1 - t\_0}, \frac{1}{1 + t\_0}\right)\\
\left(-s\right) \cdot \log \left(\frac{-1 + {t\_1}^{-2}}{\frac{1}{t\_1} - -1}\right)
\end{array}
\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. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right)} \]
    2. sub-negN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} + \left(\mathsf{neg}\left(1\right)\right)\right)} \]
    3. metadata-evalN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} + \color{blue}{-1}\right) \]
    4. flip-+N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\frac{\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} \cdot \frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - -1 \cdot -1}{\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - -1}\right)} \]
  4. Applied rewrites98.8%

    \[\leadsto \left(-s\right) \cdot \log \color{blue}{\left(\frac{{\left(\mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{1 + e^{\frac{\pi}{s}}}, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)\right)}^{-2} + -1}{\frac{1}{\mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{1 + e^{\frac{\pi}{s}}}, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)} - -1}\right)} \]
  5. Final simplification98.8%

    \[\leadsto \left(-s\right) \cdot \log \left(\frac{-1 + {\left(\mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{1}{-1 - e^{\frac{\pi}{s}}}, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)\right)}^{-2}}{\frac{1}{\mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{1}{-1 - e^{\frac{\pi}{s}}}, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)} - -1}\right) \]
  6. Add Preprocessing

Alternative 2: 98.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(-1 + \frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{1}{-1 - e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\pi \cdot \frac{1}{s}}}}\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))))))
      (/ 1.0 (+ 1.0 (exp (* PI (/ 1.0 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)))))) + (1.0f / (1.0f + expf((((float) M_PI) * (1.0f / s)))))))));
}
function code(u, s)
	return Float32(Float32(-s) * log(Float32(Float32(-1.0) + Float32(Float32(1.0) / Float32(Float32(u * Float32(Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) / Float32(-s))))) + Float32(Float32(1.0) / Float32(Float32(-1.0) - exp(Float32(Float32(pi) / s)))))) + Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) * Float32(Float32(1.0) / 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)))))) + (single(1.0) / (single(1.0) + exp((single(pi) * (single(1.0) / s)))))))));
end
\begin{array}{l}

\\
\left(-s\right) \cdot \log \left(-1 + \frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{1}{-1 - e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\pi \cdot \frac{1}{s}}}}\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. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}}}} - 1\right) \]
    2. clear-numN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\color{blue}{\frac{1}{\frac{s}{\mathsf{PI}\left(\right)}}}}}} - 1\right) \]
    3. associate-/r/N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\color{blue}{\frac{1}{s} \cdot \mathsf{PI}\left(\right)}}}} - 1\right) \]
    4. lower-*.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\color{blue}{\frac{1}{s} \cdot \mathsf{PI}\left(\right)}}}} - 1\right) \]
    5. lower-/.f3298.7

      \[\leadsto \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^{\color{blue}{\frac{1}{s}} \cdot \pi}}} - 1\right) \]
  4. Applied rewrites98.7%

    \[\leadsto \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^{\color{blue}{\frac{1}{s} \cdot \pi}}}} - 1\right) \]
  5. Final simplification98.7%

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

Alternative 3: 98.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{\pi}{s}}\\
\left(-s\right) \cdot \log \left(-1 + \frac{1}{\frac{u}{1 + e^{\frac{\pi}{-s}}} + \left(\frac{1}{1 + t\_0} + \frac{u}{-1 - t\_0}\right)}\right)
\end{array}
\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. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right)} \]
  4. Applied rewrites98.6%

    \[\leadsto \left(-s\right) \cdot \log \color{blue}{\left(\mathsf{expm1}\left(-\log \left(\mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{1 + e^{\frac{\pi}{s}}}, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)\right)\right)\right)} \]
  5. Applied rewrites98.7%

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

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

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

Alternative 4: 97.6% accurate, 1.4× speedup?

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

\\
\left(-s\right) \cdot \log \left(-1 + \frac{1}{\frac{u}{1 + e^{\frac{\pi}{-s}}} + \frac{u}{-1 - e^{\frac{\pi}{s}}}}\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. Add Preprocessing
  3. Taylor expanded in u around inf

    \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{u \cdot \left(\frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)}} - 1\right) \]
  4. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{u \cdot \left(\frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)}} - 1\right) \]
    2. sub-negN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \color{blue}{\left(\frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)}} - 1\right) \]
    3. lower-+.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \color{blue}{\left(\frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)}} - 1\right) \]
    4. lower-/.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\color{blue}{\frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    5. lower-+.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{\color{blue}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    6. lower-exp.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + \color{blue}{e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    7. mul-1-negN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\color{blue}{\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{s}\right)}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    8. distribute-neg-frac2N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\color{blue}{\frac{\mathsf{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    9. mul-1-negN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{\color{blue}{-1 \cdot s}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    10. lower-/.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\color{blue}{\frac{\mathsf{PI}\left(\right)}{-1 \cdot s}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    11. lower-PI.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\color{blue}{\mathsf{PI}\left(\right)}}{-1 \cdot s}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    12. mul-1-negN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{\color{blue}{\mathsf{neg}\left(s\right)}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    13. lower-neg.f32N/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{\color{blue}{\mathsf{neg}\left(s\right)}}}} + \left(\mathsf{neg}\left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)\right)\right)} - 1\right) \]
    14. distribute-neg-fracN/A

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}} + \color{blue}{\frac{\mathsf{neg}\left(1\right)}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}}\right)} - 1\right) \]
  5. Applied rewrites96.9%

    \[\leadsto \left(-s\right) \cdot \log \left(\frac{1}{\color{blue}{u \cdot \left(\frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{1 + e^{\frac{\pi}{s}}}\right)}} - 1\right) \]
  6. Step-by-step derivation
    1. Applied rewrites96.9%

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

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

    Alternative 5: 25.1% accurate, 3.9× speedup?

    \[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\pi \cdot 0.25, \frac{4}{s}, 1\right)\right) \end{array} \]
    (FPCore (u s)
     :precision binary32
     (* (- s) (log (fma (* PI 0.25) (/ 4.0 s) 1.0))))
    float code(float u, float s) {
    	return -s * logf(fmaf((((float) M_PI) * 0.25f), (4.0f / s), 1.0f));
    }
    
    function code(u, s)
    	return Float32(Float32(-s) * log(fma(Float32(Float32(pi) * Float32(0.25)), Float32(Float32(4.0) / s), Float32(1.0))))
    end
    
    \begin{array}{l}
    
    \\
    \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\pi \cdot 0.25, \frac{4}{s}, 1\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. Add Preprocessing
    3. Taylor expanded in s around -inf

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(1 + 4 \cdot \frac{u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)}{s}\right)} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(1 + \color{blue}{\frac{4 \cdot \left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}}\right) \]
      2. +-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\frac{4 \cdot \left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s} + 1\right)} \]
      3. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{\color{blue}{\left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot 4}}{s} + 1\right) \]
      4. associate-/l*N/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\color{blue}{\left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{4}{s}} + 1\right) \]
      5. lower-fma.f32N/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\mathsf{fma}\left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right), \frac{4}{s}, 1\right)\right)} \]
    5. Applied rewrites24.8%

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\mathsf{fma}\left(\frac{1}{4} \cdot \mathsf{PI}\left(\right), \frac{\color{blue}{4}}{s}, 1\right)\right) \]
    7. Step-by-step derivation
      1. Applied rewrites25.0%

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

        \[\leadsto \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\pi \cdot 0.25, \frac{4}{s}, 1\right)\right) \]
      3. Add Preprocessing

      Alternative 6: 25.1% accurate, 4.2× speedup?

      \[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(1 + \frac{\pi}{s}\right) \end{array} \]
      (FPCore (u s) :precision binary32 (* (- s) (log (+ 1.0 (/ PI s)))))
      float code(float u, float s) {
      	return -s * logf((1.0f + (((float) M_PI) / s)));
      }
      
      function code(u, s)
      	return Float32(Float32(-s) * log(Float32(Float32(1.0) + Float32(Float32(pi) / s))))
      end
      
      function tmp = code(u, s)
      	tmp = -s * log((single(1.0) + (single(pi) / s)));
      end
      
      \begin{array}{l}
      
      \\
      \left(-s\right) \cdot \log \left(1 + \frac{\pi}{s}\right)
      \end{array}
      
      Derivation
      1. Initial program 98.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. Add Preprocessing
      3. Taylor expanded in s around inf

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(1 + -4 \cdot \frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)}{s}\right)} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(-4 \cdot \frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)}{s} + 1\right)} \]
        2. lower-fma.f32N/A

          \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\mathsf{fma}\left(-4, \frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)}{s}, 1\right)\right)} \]
      5. Applied rewrites24.8%

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

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(1 + \color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}\right) \]
      7. Step-by-step derivation
        1. Applied rewrites25.0%

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

        Alternative 7: 11.6% accurate, 23.2× speedup?

        \[\begin{array}{l} \\ -4 \cdot \mathsf{fma}\left(\pi, 0.25, \pi \cdot \left(u \cdot -0.5\right)\right) \end{array} \]
        (FPCore (u s) :precision binary32 (* -4.0 (fma PI 0.25 (* PI (* u -0.5)))))
        float code(float u, float s) {
        	return -4.0f * fmaf(((float) M_PI), 0.25f, (((float) M_PI) * (u * -0.5f)));
        }
        
        function code(u, s)
        	return Float32(Float32(-4.0) * fma(Float32(pi), Float32(0.25), Float32(Float32(pi) * Float32(u * Float32(-0.5)))))
        end
        
        \begin{array}{l}
        
        \\
        -4 \cdot \mathsf{fma}\left(\pi, 0.25, \pi \cdot \left(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. Add Preprocessing
        3. Taylor expanded in s around -inf

          \[\leadsto \color{blue}{-4 \cdot \left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{\left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot -4} \]
          2. lower-*.f32N/A

            \[\leadsto \color{blue}{\left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot -4} \]
          3. cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right)} \cdot -4 \]
          4. metadata-evalN/A

            \[\leadsto \left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) + \color{blue}{\frac{1}{4}} \cdot \mathsf{PI}\left(\right)\right) \cdot -4 \]
          5. +-commutativeN/A

            \[\leadsto \color{blue}{\left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) + u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)\right)} \cdot -4 \]
          6. *-commutativeN/A

            \[\leadsto \left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{4}} + u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)\right) \cdot -4 \]
          7. lower-fma.f32N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)\right)} \cdot -4 \]
          8. lower-PI.f32N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)}, \frac{1}{4}, u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)\right) \cdot -4 \]
          9. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, \color{blue}{\left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot u}\right) \cdot -4 \]
          10. distribute-rgt-out--N/A

            \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(\frac{-1}{4} - \frac{1}{4}\right)\right)} \cdot u\right) \cdot -4 \]
          11. metadata-evalN/A

            \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{-1}{2}}\right) \cdot u\right) \cdot -4 \]
          12. associate-*l*N/A

            \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, \color{blue}{\mathsf{PI}\left(\right) \cdot \left(\frac{-1}{2} \cdot u\right)}\right) \cdot -4 \]
          13. lower-*.f32N/A

            \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, \color{blue}{\mathsf{PI}\left(\right) \cdot \left(\frac{-1}{2} \cdot u\right)}\right) \cdot -4 \]
          14. lower-PI.f32N/A

            \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{4}, \color{blue}{\mathsf{PI}\left(\right)} \cdot \left(\frac{-1}{2} \cdot u\right)\right) \cdot -4 \]
          15. lower-*.f3212.3

            \[\leadsto \mathsf{fma}\left(\pi, 0.25, \pi \cdot \color{blue}{\left(-0.5 \cdot u\right)}\right) \cdot -4 \]
        5. Applied rewrites12.3%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\pi, 0.25, \pi \cdot \left(-0.5 \cdot u\right)\right) \cdot -4} \]
        6. Final simplification12.3%

          \[\leadsto -4 \cdot \mathsf{fma}\left(\pi, 0.25, \pi \cdot \left(u \cdot -0.5\right)\right) \]
        7. Add Preprocessing

        Alternative 8: 11.6% accurate, 23.2× speedup?

        \[\begin{array}{l} \\ 4 \cdot \mathsf{fma}\left(\pi, u \cdot 0.5, \pi \cdot -0.25\right) \end{array} \]
        (FPCore (u s) :precision binary32 (* 4.0 (fma PI (* u 0.5) (* PI -0.25))))
        float code(float u, float s) {
        	return 4.0f * fmaf(((float) M_PI), (u * 0.5f), (((float) M_PI) * -0.25f));
        }
        
        function code(u, s)
        	return Float32(Float32(4.0) * fma(Float32(pi), Float32(u * Float32(0.5)), Float32(Float32(pi) * Float32(-0.25))))
        end
        
        \begin{array}{l}
        
        \\
        4 \cdot \mathsf{fma}\left(\pi, u \cdot 0.5, \pi \cdot -0.25\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. Add Preprocessing
        3. Taylor expanded in s around inf

          \[\leadsto \color{blue}{4 \cdot \left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)} \]
        4. Step-by-step derivation
          1. lower-*.f32N/A

            \[\leadsto \color{blue}{4 \cdot \left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)} \]
          2. cancel-sign-sub-invN/A

            \[\leadsto 4 \cdot \color{blue}{\left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right)} \]
          3. *-commutativeN/A

            \[\leadsto 4 \cdot \left(\color{blue}{\left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot u} + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right) \]
          4. distribute-rgt-out--N/A

            \[\leadsto 4 \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{4} - \frac{-1}{4}\right)\right)} \cdot u + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right) \]
          5. metadata-evalN/A

            \[\leadsto 4 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}\right) \cdot u + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right) \]
          6. associate-*l*N/A

            \[\leadsto 4 \cdot \left(\color{blue}{\mathsf{PI}\left(\right) \cdot \left(\frac{1}{2} \cdot u\right)} + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right) \]
          7. metadata-evalN/A

            \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{2} \cdot u\right) + \color{blue}{\frac{-1}{4}} \cdot \mathsf{PI}\left(\right)\right) \]
          8. lower-fma.f32N/A

            \[\leadsto 4 \cdot \color{blue}{\mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{2} \cdot u, \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)} \]
          9. lower-PI.f32N/A

            \[\leadsto 4 \cdot \mathsf{fma}\left(\color{blue}{\mathsf{PI}\left(\right)}, \frac{1}{2} \cdot u, \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \]
          10. lower-*.f32N/A

            \[\leadsto 4 \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right), \color{blue}{\frac{1}{2} \cdot u}, \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) \]
          11. *-commutativeN/A

            \[\leadsto 4 \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{2} \cdot u, \color{blue}{\mathsf{PI}\left(\right) \cdot \frac{-1}{4}}\right) \]
          12. lower-*.f32N/A

            \[\leadsto 4 \cdot \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{2} \cdot u, \color{blue}{\mathsf{PI}\left(\right) \cdot \frac{-1}{4}}\right) \]
          13. lower-PI.f3212.3

            \[\leadsto 4 \cdot \mathsf{fma}\left(\pi, 0.5 \cdot u, \color{blue}{\pi} \cdot -0.25\right) \]
        5. Applied rewrites12.3%

          \[\leadsto \color{blue}{4 \cdot \mathsf{fma}\left(\pi, 0.5 \cdot u, \pi \cdot -0.25\right)} \]
        6. Final simplification12.3%

          \[\leadsto 4 \cdot \mathsf{fma}\left(\pi, u \cdot 0.5, \pi \cdot -0.25\right) \]
        7. Add Preprocessing

        Alternative 9: 11.3% accurate, 170.0× 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. Add Preprocessing
        3. Taylor expanded in u around 0

          \[\leadsto \color{blue}{-1 \cdot \mathsf{PI}\left(\right)} \]
        4. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)} \]
          2. lower-neg.f32N/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)} \]
          3. lower-PI.f3212.0

            \[\leadsto -\color{blue}{\pi} \]
        5. Applied rewrites12.0%

          \[\leadsto \color{blue}{-\pi} \]
        6. Add Preprocessing

        Alternative 10: 10.3% accurate, 510.0× speedup?

        \[\begin{array}{l} \\ 0 \end{array} \]
        (FPCore (u s) :precision binary32 0.0)
        float code(float u, float s) {
        	return 0.0f;
        }
        
        real(4) function code(u, s)
            real(4), intent (in) :: u
            real(4), intent (in) :: s
            code = 0.0e0
        end function
        
        function code(u, s)
        	return Float32(0.0)
        end
        
        function tmp = code(u, s)
        	tmp = single(0.0);
        end
        
        \begin{array}{l}
        
        \\
        0
        \end{array}
        
        Derivation
        1. Initial program 98.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. Add Preprocessing
        3. Step-by-step derivation
          1. lift--.f32N/A

            \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right)} \]
        4. Applied rewrites98.6%

          \[\leadsto \left(-s\right) \cdot \log \color{blue}{\left(\mathsf{expm1}\left(-\log \left(\mathsf{fma}\left(u, \frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{1 + e^{\frac{\pi}{s}}}, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)\right)\right)\right)} \]
        5. Taylor expanded in s around inf

          \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \log \left(e^{\mathsf{neg}\left(\log \frac{1}{2}\right)} - 1\right)\right)} \]
        6. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(s \cdot \log \left(e^{\mathsf{neg}\left(\log \frac{1}{2}\right)} - 1\right)\right)} \]
          2. distribute-rgt-neg-inN/A

            \[\leadsto \color{blue}{s \cdot \left(\mathsf{neg}\left(\log \left(e^{\mathsf{neg}\left(\log \frac{1}{2}\right)} - 1\right)\right)\right)} \]
          3. exp-negN/A

            \[\leadsto s \cdot \left(\mathsf{neg}\left(\log \left(\color{blue}{\frac{1}{e^{\log \frac{1}{2}}}} - 1\right)\right)\right) \]
          4. rem-exp-logN/A

            \[\leadsto s \cdot \left(\mathsf{neg}\left(\log \left(\frac{1}{\color{blue}{\frac{1}{2}}} - 1\right)\right)\right) \]
          5. metadata-evalN/A

            \[\leadsto s \cdot \left(\mathsf{neg}\left(\log \left(\color{blue}{2} - 1\right)\right)\right) \]
          6. metadata-evalN/A

            \[\leadsto s \cdot \left(\mathsf{neg}\left(\log \color{blue}{1}\right)\right) \]
          7. metadata-evalN/A

            \[\leadsto s \cdot \left(\mathsf{neg}\left(\color{blue}{0}\right)\right) \]
          8. metadata-evalN/A

            \[\leadsto s \cdot \color{blue}{0} \]
          9. lower-*.f329.9

            \[\leadsto \color{blue}{s \cdot 0} \]
        7. Applied rewrites9.9%

          \[\leadsto \color{blue}{s \cdot 0} \]
        8. Applied rewrites9.9%

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

        Reproduce

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