Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 99.0% → 99.0%
Time: 16.5s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 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.0× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. 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(\left(\frac{1}{u \cdot \left(1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)} + \frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}}\right) - \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(\left(\frac{1}{u \cdot \left(1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)} + \frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}}\right) - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)}} - 1\right) \]
    2. associate--l+N/A

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 98.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(-1 + \frac{1}{\frac{1}{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
     (+ (/ 1.0 (+ 1.0 (exp (/ PI s)))) (/ u (+ 1.0 (exp (/ PI (- s)))))))))))
float code(float u, float s) {
	return -s * logf((-1.0f + (1.0f / ((1.0f / (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(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) / s)))) + Float32(u / Float32(Float32(1.0) + exp(Float32(Float32(pi) / Float32(-s))))))))))
end
function tmp = code(u, s)
	tmp = -s * log((single(-1.0) + (single(1.0) / ((single(1.0) / (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{1}{1 + e^{\frac{\pi}{s}}} + \frac{u}{1 + e^{\frac{\pi}{-s}}}}\right)
\end{array}
Derivation
  1. Initial program 98.8%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. Applied rewrites98.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 4: 97.1% accurate, 1.5× 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}{2 + \frac{\pi + \mathsf{fma}\left(0.16666666666666666, \frac{\pi \cdot \left(\pi \cdot \pi\right)}{s \cdot s}, 0.5 \cdot \frac{\pi \cdot \pi}{s}\right)}{s}}\right)}\right) \end{array} \]
    (FPCore (u s)
     :precision binary32
     (*
      (- s)
      (log
       (+
        -1.0
        (/
         1.0
         (*
          u
          (+
           (/ 1.0 (+ 1.0 (exp (/ PI (- s)))))
           (/
            -1.0
            (+
             2.0
             (/
              (+
               PI
               (fma
                0.16666666666666666
                (/ (* PI (* PI PI)) (* s s))
                (* 0.5 (/ (* PI PI) s))))
              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 / (2.0f + ((((float) M_PI) + fmaf(0.16666666666666666f, ((((float) M_PI) * (((float) M_PI) * ((float) M_PI))) / (s * s)), (0.5f * ((((float) M_PI) * ((float) M_PI)) / s)))) / s))))))));
    }
    
    function code(u, s)
    	return Float32(Float32(-s) * log(Float32(Float32(-1.0) + Float32(Float32(1.0) / Float32(u * Float32(Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) / Float32(-s))))) + Float32(Float32(-1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(pi) + fma(Float32(0.16666666666666666), Float32(Float32(Float32(pi) * Float32(Float32(pi) * Float32(pi))) / Float32(s * s)), Float32(Float32(0.5) * Float32(Float32(Float32(pi) * Float32(pi)) / s)))) / 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}{2 + \frac{\pi + \mathsf{fma}\left(0.16666666666666666, \frac{\pi \cdot \left(\pi \cdot \pi\right)}{s \cdot s}, 0.5 \cdot \frac{\pi \cdot \pi}{s}\right)}{s}}\right)}\right)
    \end{array}
    
    Derivation
    1. Initial program 98.8%

      \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. Applied rewrites98.8%

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

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

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

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

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

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

        \[\leadsto \left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{1 + \color{blue}{\left(1 - \frac{-\left(\pi + \frac{\mathsf{fma}\left(0.16666666666666666, \frac{\pi \cdot \left(\pi \cdot \pi\right)}{s}, 0.5 \cdot \left(\pi \cdot \pi\right)\right)}{s}\right)}{s}\right)}}, u, \frac{1}{1 + e^{\frac{\pi}{s}}}\right)} - 1\right) \]
      5. 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}{2 - -1 \cdot \frac{\mathsf{PI}\left(\right) + \left(\frac{1}{6} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{{s}^{2}} + \frac{1}{2} \cdot \frac{{\mathsf{PI}\left(\right)}^{2}}{s}\right)}{s}}\right)}} - 1\right) \]
      6. Applied rewrites96.6%

        \[\leadsto \left(-s\right) \cdot \log \left(\frac{1}{\color{blue}{u \cdot \left(\frac{1}{1 + e^{\frac{\pi}{-s}}} + \frac{-1}{2 + \frac{\pi + \mathsf{fma}\left(0.16666666666666666, \frac{\pi \cdot \left(\pi \cdot \pi\right)}{s \cdot s}, 0.5 \cdot \frac{\pi \cdot \pi}{s}\right)}{s}}\right)}} - 1\right) \]
      7. Final simplification96.6%

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

      Alternative 5: 11.6% accurate, 4.2× speedup?

      \[\begin{array}{l} \\ 4 \cdot \left(\left(\pi \cdot \log e\right) \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right) \end{array} \]
      (FPCore (u s) :precision binary32 (* 4.0 (* (* PI (log E)) (fma 0.5 u -0.25))))
      float code(float u, float s) {
      	return 4.0f * ((((float) M_PI) * logf(((float) M_E))) * fmaf(0.5f, u, -0.25f));
      }
      
      function code(u, s)
      	return Float32(Float32(4.0) * Float32(Float32(Float32(pi) * log(Float32(exp(1)))) * fma(Float32(0.5), u, Float32(-0.25))))
      end
      
      \begin{array}{l}
      
      \\
      4 \cdot \left(\left(\pi \cdot \log e\right) \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 98.8%

        \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in s around inf

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 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}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
        2. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{4 \cdot \left(\frac{1}{2} \cdot \left(u \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(\frac{1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right)} \]
        3. associate-*r*N/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{4 \cdot \left(\pi \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right)} \]
      9. Step-by-step derivation
        1. add-log-expN/A

          \[\leadsto 4 \cdot \left(\color{blue}{\log \left(e^{\mathsf{PI}\left(\right)}\right)} \cdot \mathsf{fma}\left(\frac{1}{2}, u, \frac{-1}{4}\right)\right) \]
        2. *-un-lft-identityN/A

          \[\leadsto 4 \cdot \left(\log \left(e^{\color{blue}{1 \cdot \mathsf{PI}\left(\right)}}\right) \cdot \mathsf{fma}\left(\frac{1}{2}, u, \frac{-1}{4}\right)\right) \]
        3. lift-PI.f32N/A

          \[\leadsto 4 \cdot \left(\log \left(e^{1 \cdot \color{blue}{\mathsf{PI}\left(\right)}}\right) \cdot \mathsf{fma}\left(\frac{1}{2}, u, \frac{-1}{4}\right)\right) \]
        4. exp-prodN/A

          \[\leadsto 4 \cdot \left(\log \color{blue}{\left({\left(e^{1}\right)}^{\mathsf{PI}\left(\right)}\right)} \cdot \mathsf{fma}\left(\frac{1}{2}, u, \frac{-1}{4}\right)\right) \]
        5. log-powN/A

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

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

          \[\leadsto 4 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\log \left(e^{1}\right)}\right) \cdot \mathsf{fma}\left(\frac{1}{2}, u, \frac{-1}{4}\right)\right) \]
        8. exp-1-eN/A

          \[\leadsto 4 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \log \color{blue}{\mathsf{E}\left(\right)}\right) \cdot \mathsf{fma}\left(\frac{1}{2}, u, \frac{-1}{4}\right)\right) \]
        9. lower-E.f3211.7

          \[\leadsto 4 \cdot \left(\left(\pi \cdot \log \color{blue}{e}\right) \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right) \]
      10. Applied rewrites11.7%

        \[\leadsto 4 \cdot \left(\color{blue}{\left(\pi \cdot \log e\right)} \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right) \]
      11. Add Preprocessing

      Alternative 6: 11.6% accurate, 4.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(0.25, u \cdot u, 0.0625\right)\\ 4 \cdot \left(\pi \cdot \frac{\mathsf{fma}\left(u \cdot \left(u \cdot u\right), 0.125, -0.015625\right)}{\frac{t\_0 \cdot t\_0 - \left(u \cdot 0.125\right) \cdot \left(u \cdot 0.125\right)}{t\_0 - u \cdot 0.125}}\right) \end{array} \end{array} \]
      (FPCore (u s)
       :precision binary32
       (let* ((t_0 (fma 0.25 (* u u) 0.0625)))
         (*
          4.0
          (*
           PI
           (/
            (fma (* u (* u u)) 0.125 -0.015625)
            (/ (- (* t_0 t_0) (* (* u 0.125) (* u 0.125))) (- t_0 (* u 0.125))))))))
      float code(float u, float s) {
      	float t_0 = fmaf(0.25f, (u * u), 0.0625f);
      	return 4.0f * (((float) M_PI) * (fmaf((u * (u * u)), 0.125f, -0.015625f) / (((t_0 * t_0) - ((u * 0.125f) * (u * 0.125f))) / (t_0 - (u * 0.125f)))));
      }
      
      function code(u, s)
      	t_0 = fma(Float32(0.25), Float32(u * u), Float32(0.0625))
      	return Float32(Float32(4.0) * Float32(Float32(pi) * Float32(fma(Float32(u * Float32(u * u)), Float32(0.125), Float32(-0.015625)) / Float32(Float32(Float32(t_0 * t_0) - Float32(Float32(u * Float32(0.125)) * Float32(u * Float32(0.125)))) / Float32(t_0 - Float32(u * Float32(0.125)))))))
      end
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \mathsf{fma}\left(0.25, u \cdot u, 0.0625\right)\\
      4 \cdot \left(\pi \cdot \frac{\mathsf{fma}\left(u \cdot \left(u \cdot u\right), 0.125, -0.015625\right)}{\frac{t\_0 \cdot t\_0 - \left(u \cdot 0.125\right) \cdot \left(u \cdot 0.125\right)}{t\_0 - u \cdot 0.125}}\right)
      \end{array}
      \end{array}
      
      Derivation
      1. Initial program 98.8%

        \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in s around inf

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 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}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
        2. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{4 \cdot \left(\frac{1}{2} \cdot \left(u \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(\frac{1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right)} \]
        3. associate-*r*N/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{4 \cdot \left(\pi \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right)} \]
      9. Step-by-step derivation
        1. flip3-+N/A

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

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{{\color{blue}{\left(u \cdot \frac{1}{2}\right)}}^{3} + {\frac{-1}{4}}^{3}}{\left(\frac{1}{2} \cdot u\right) \cdot \left(\frac{1}{2} \cdot u\right) + \left(\frac{-1}{4} \cdot \frac{-1}{4} - \left(\frac{1}{2} \cdot u\right) \cdot \frac{-1}{4}\right)}\right) \]
        4. unpow-prod-downN/A

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\color{blue}{\mathsf{fma}\left({u}^{3}, {\frac{1}{2}}^{3}, {\frac{-1}{4}}^{3}\right)}}{\left(\frac{1}{2} \cdot u\right) \cdot \left(\frac{1}{2} \cdot u\right) + \left(\frac{-1}{4} \cdot \frac{-1}{4} - \left(\frac{1}{2} \cdot u\right) \cdot \frac{-1}{4}\right)}\right) \]
        6. unpow3N/A

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

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

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, \color{blue}{\frac{1}{8}}, {\frac{-1}{4}}^{3}\right)}{\left(\frac{1}{2} \cdot u\right) \cdot \left(\frac{1}{2} \cdot u\right) + \left(\frac{-1}{4} \cdot \frac{-1}{4} - \left(\frac{1}{2} \cdot u\right) \cdot \frac{-1}{4}\right)}\right) \]
        10. metadata-evalN/A

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, \frac{1}{8}, \color{blue}{\frac{-1}{64}}\right)}{\left(\frac{1}{2} \cdot u\right) \cdot \left(\frac{1}{2} \cdot u\right) + \left(\frac{-1}{4} \cdot \frac{-1}{4} - \left(\frac{1}{2} \cdot u\right) \cdot \frac{-1}{4}\right)}\right) \]
        11. associate-+r-N/A

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, \frac{1}{8}, \frac{-1}{64}\right)}{\color{blue}{\left(\left(\frac{1}{2} \cdot u\right) \cdot \left(\frac{1}{2} \cdot u\right) + \frac{-1}{4} \cdot \frac{-1}{4}\right) - \left(\frac{1}{2} \cdot u\right) \cdot \frac{-1}{4}}}\right) \]
        13. swap-sqrN/A

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

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

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

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

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

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

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

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

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, \frac{1}{8}, \frac{-1}{64}\right)}{\mathsf{fma}\left(\frac{1}{4}, u \cdot u, \frac{1}{16}\right) - \color{blue}{u \cdot \left(\frac{1}{2} \cdot \frac{-1}{4}\right)}}\right) \]
        23. metadata-eval11.7

          \[\leadsto 4 \cdot \left(\pi \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, 0.125, -0.015625\right)}{\mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) - u \cdot \color{blue}{-0.125}}\right) \]
      10. Applied rewrites11.7%

        \[\leadsto 4 \cdot \left(\pi \cdot \color{blue}{\frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, 0.125, -0.015625\right)}{\mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) - u \cdot -0.125}}\right) \]
      11. Step-by-step derivation
        1. lift-*.f32N/A

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

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

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, \frac{1}{8}, \frac{-1}{64}\right)}{\color{blue}{\mathsf{fma}\left(\frac{1}{4}, u \cdot u, \frac{1}{16}\right) + \left(\mathsf{neg}\left(u \cdot \frac{-1}{8}\right)\right)}}\right) \]
        5. flip-+N/A

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

          \[\leadsto 4 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, \frac{1}{8}, \frac{-1}{64}\right)}{\color{blue}{\frac{\mathsf{fma}\left(\frac{1}{4}, u \cdot u, \frac{1}{16}\right) \cdot \mathsf{fma}\left(\frac{1}{4}, u \cdot u, \frac{1}{16}\right) - \left(\mathsf{neg}\left(u \cdot \frac{-1}{8}\right)\right) \cdot \left(\mathsf{neg}\left(u \cdot \frac{-1}{8}\right)\right)}{\mathsf{fma}\left(\frac{1}{4}, u \cdot u, \frac{1}{16}\right) - \left(\mathsf{neg}\left(u \cdot \frac{-1}{8}\right)\right)}}}\right) \]
      12. Applied rewrites11.7%

        \[\leadsto 4 \cdot \left(\pi \cdot \frac{\mathsf{fma}\left(\left(u \cdot u\right) \cdot u, 0.125, -0.015625\right)}{\color{blue}{\frac{\mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) \cdot \mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) - \left(u \cdot 0.125\right) \cdot \left(u \cdot 0.125\right)}{\mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) - u \cdot 0.125}}}\right) \]
      13. Final simplification11.7%

        \[\leadsto 4 \cdot \left(\pi \cdot \frac{\mathsf{fma}\left(u \cdot \left(u \cdot u\right), 0.125, -0.015625\right)}{\frac{\mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) \cdot \mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) - \left(u \cdot 0.125\right) \cdot \left(u \cdot 0.125\right)}{\mathsf{fma}\left(0.25, u \cdot u, 0.0625\right) - u \cdot 0.125}}\right) \]
      14. Add Preprocessing

      Alternative 7: 11.6% accurate, 42.5× speedup?

      \[\begin{array}{l} \\ \pi \cdot \mathsf{fma}\left(2, u, -1\right) \end{array} \]
      (FPCore (u s) :precision binary32 (* PI (fma 2.0 u -1.0)))
      float code(float u, float s) {
      	return ((float) M_PI) * fmaf(2.0f, u, -1.0f);
      }
      
      function code(u, s)
      	return Float32(Float32(pi) * fma(Float32(2.0), u, Float32(-1.0)))
      end
      
      \begin{array}{l}
      
      \\
      \pi \cdot \mathsf{fma}\left(2, u, -1\right)
      \end{array}
      
      Derivation
      1. Initial program 98.8%

        \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in s around inf

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 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}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
        2. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{4 \cdot \left(\frac{1}{2} \cdot \left(u \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(\frac{1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \mathsf{PI}\left(\right)\right)} \]
        3. associate-*r*N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\left(2 \cdot u\right) \cdot \mathsf{PI}\left(\right)} + -1 \cdot \mathsf{PI}\left(\right) \]
        3. distribute-rgt-outN/A

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

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

          \[\leadsto \color{blue}{\mathsf{PI}\left(\right)} \cdot \left(2 \cdot u + -1\right) \]
        6. lower-fma.f3211.7

          \[\leadsto \pi \cdot \color{blue}{\mathsf{fma}\left(2, u, -1\right)} \]
      11. Applied rewrites11.7%

        \[\leadsto \color{blue}{\pi \cdot \mathsf{fma}\left(2, u, -1\right)} \]
      12. Add Preprocessing

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

        \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
      2. 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.f3211.5

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

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

      Alternative 9: 4.6% accurate, 510.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(pi)
      end
      
      function tmp = code(u, s)
      	tmp = single(pi);
      end
      
      \begin{array}{l}
      
      \\
      \pi
      \end{array}
      
      Derivation
      1. Initial program 98.8%

        \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in s around inf

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 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}{\frac{u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right)}{s}} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
        2. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{PI}\left(\right)} \]
      8. Step-by-step derivation
        1. lower-PI.f324.7

          \[\leadsto \color{blue}{\pi} \]
      9. Applied rewrites4.7%

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

      Reproduce

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