Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 17.7s
Alternatives: 13
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 13 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. 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)} \]
  4. 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) \]
  5. 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-PI.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^{\frac{\color{blue}{\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{1}{1 + t\_0} + \left(\frac{u}{1 + e^{\frac{\pi}{-s}}} + \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
       (+
        (/ 1.0 (+ 1.0 t_0))
        (+ (/ u (+ 1.0 (exp (/ PI (- s))))) (/ 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 / ((1.0f / (1.0f + t_0)) + ((u / (1.0f + expf((((float) M_PI) / -s)))) + (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(Float32(1.0) / Float32(Float32(1.0) + t_0)) + Float32(Float32(u / Float32(Float32(1.0) + exp(Float32(Float32(pi) / Float32(-s))))) + 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) / ((single(1.0) / (single(1.0) + t_0)) + ((u / (single(1.0) + exp((single(pi) / -s)))) + (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{1}{1 + t\_0} + \left(\frac{u}{1 + e^{\frac{\pi}{-s}}} + \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. 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)} \]
  4. Applied rewrites98.7%

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

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

    \[\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) \]
  7. 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. lift-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)}}{\mathsf{neg}\left(s\right)}}} + \frac{-1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)} - 1\right) \]
    2. lift-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)}}}} + \frac{-1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)} - 1\right) \]
    3. lift-/.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)}{\mathsf{neg}\left(s\right)}}}} + \frac{-1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)} - 1\right) \]
    4. lift-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^{\frac{\mathsf{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}}} + \frac{-1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)} - 1\right) \]
    5. lift-+.f32N/A

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{u \cdot \left(\color{blue}{\frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}}} + \frac{-1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right)} - 1\right) \]
    7. lift-PI.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)}{\mathsf{neg}\left(s\right)}}} + \frac{-1}{1 + e^{\frac{\color{blue}{\mathsf{PI}\left(\right)}}{s}}}\right)} - 1\right) \]
    8. 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{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}} + \frac{-1}{1 + e^{\color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}}}\right)} - 1\right) \]
    9. lift-exp.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)}{\mathsf{neg}\left(s\right)}}} + \frac{-1}{1 + \color{blue}{e^{\frac{\mathsf{PI}\left(\right)}{s}}}}\right)} - 1\right) \]
    10. 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{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}} + \frac{-1}{\color{blue}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}}\right)} - 1\right) \]
    11. 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{PI}\left(\right)}{\mathsf{neg}\left(s\right)}}} + \color{blue}{\frac{-1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}}\right)} - 1\right) \]
  7. Applied rewrites96.9%

    \[\leadsto \left(-s\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{u}{1 + e^{\frac{\pi}{-s}}} + \frac{u}{-\left(1 + e^{\frac{\pi}{s}}\right)}}} - 1\right) \]
  8. 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) \]
  9. Add Preprocessing

Alternative 5: 25.2% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := s + s \cdot \frac{\pi}{s}\\ \left(-s\right) \cdot \mathsf{fma}\left(u, -2 \cdot \left(\frac{\pi}{t\_0} + \frac{u \cdot \left(\pi \cdot \pi\right)}{t\_0 \cdot t\_0}\right), \mathsf{log1p}\left(\frac{\pi}{s}\right)\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (+ s (* s (/ PI s)))))
   (*
    (- s)
    (fma
     u
     (* -2.0 (+ (/ PI t_0) (/ (* u (* PI PI)) (* t_0 t_0))))
     (log1p (/ PI s))))))
float code(float u, float s) {
	float t_0 = s + (s * (((float) M_PI) / s));
	return -s * fmaf(u, (-2.0f * ((((float) M_PI) / t_0) + ((u * (((float) M_PI) * ((float) M_PI))) / (t_0 * t_0)))), log1pf((((float) M_PI) / s)));
}
function code(u, s)
	t_0 = Float32(s + Float32(s * Float32(Float32(pi) / s)))
	return Float32(Float32(-s) * fma(u, Float32(Float32(-2.0) * Float32(Float32(Float32(pi) / t_0) + Float32(Float32(u * Float32(Float32(pi) * Float32(pi))) / Float32(t_0 * t_0)))), log1p(Float32(Float32(pi) / s))))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := s + s \cdot \frac{\pi}{s}\\
\left(-s\right) \cdot \mathsf{fma}\left(u, -2 \cdot \left(\frac{\pi}{t\_0} + \frac{u \cdot \left(\pi \cdot \pi\right)}{t\_0 \cdot t\_0}\right), \mathsf{log1p}\left(\frac{\pi}{s}\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. 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 \color{blue}{\left(\log \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right) + u \cdot \left(-2 \cdot \frac{\mathsf{PI}\left(\right)}{s \cdot \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)} + -2 \cdot \frac{u \cdot {\mathsf{PI}\left(\right)}^{2}}{{s}^{2} \cdot {\left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)}^{2}}\right)\right)} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \color{blue}{\mathsf{fma}\left(u, -2 \cdot \frac{\mathsf{PI}\left(\right)}{s \cdot \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)} + -2 \cdot \frac{u \cdot {\mathsf{PI}\left(\right)}^{2}}{{s}^{2} \cdot {\left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)}^{2}}, \log \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)\right)} \]
  8. Applied rewrites25.0%

    \[\leadsto \left(-s\right) \cdot \color{blue}{\mathsf{fma}\left(u, -2 \cdot \left(\frac{\pi}{s + s \cdot \frac{\pi}{s}} + \frac{u \cdot \left(\pi \cdot \pi\right)}{\left(s + s \cdot \frac{\pi}{s}\right) \cdot \left(s + s \cdot \frac{\pi}{s}\right)}\right), \mathsf{log1p}\left(\frac{\pi}{s}\right)\right)} \]
  9. Add Preprocessing

Alternative 6: 25.2% accurate, 2.4× speedup?

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

\\
\begin{array}{l}
t_0 := 1 + \frac{\pi}{s}\\
\mathsf{fma}\left(u, 2 \cdot \left(\frac{\pi}{t\_0} + \frac{u \cdot \left(\pi \cdot \pi\right)}{s \cdot \left(t\_0 \cdot t\_0\right)}\right), \left(-s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\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. 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 \color{blue}{-1 \cdot \left(s \cdot \log \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)\right) + u \cdot \left(2 \cdot \frac{\mathsf{PI}\left(\right)}{1 + \frac{\mathsf{PI}\left(\right)}{s}} + 2 \cdot \frac{u \cdot {\mathsf{PI}\left(\right)}^{2}}{s \cdot {\left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)}^{2}}\right)} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, 2 \cdot \frac{\mathsf{PI}\left(\right)}{1 + \frac{\mathsf{PI}\left(\right)}{s}} + 2 \cdot \frac{u \cdot {\mathsf{PI}\left(\right)}^{2}}{s \cdot {\left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)}^{2}}, -1 \cdot \left(s \cdot \log \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)\right)\right)} \]
  8. Applied rewrites25.0%

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

Alternative 7: 25.1% accurate, 3.3× speedup?

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

\\
\mathsf{fma}\left(-s, \mathsf{log1p}\left(\frac{\pi}{s}\right), \frac{2 \cdot \left(u \cdot \pi\right)}{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 \color{blue}{-1 \cdot \left(s \cdot \log \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)\right) + 2 \cdot \frac{u \cdot \mathsf{PI}\left(\right)}{1 + \frac{\mathsf{PI}\left(\right)}{s}}} \]
  7. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(s\right), \mathsf{log1p}\left(\frac{\mathsf{PI}\left(\right)}{s}\right), \frac{2 \cdot \left(\mathsf{PI}\left(\right) \cdot u\right)}{1 + \color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}}\right) \]
    16. lower-PI.f3225.0

      \[\leadsto \mathsf{fma}\left(-s, \mathsf{log1p}\left(\frac{\pi}{s}\right), \frac{2 \cdot \left(\pi \cdot u\right)}{1 + \frac{\color{blue}{\pi}}{s}}\right) \]
  8. Applied rewrites25.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-s, \mathsf{log1p}\left(\frac{\pi}{s}\right), \frac{2 \cdot \left(\pi \cdot u\right)}{1 + \frac{\pi}{s}}\right)} \]
  9. Final simplification25.0%

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

Alternative 8: 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 \color{blue}{\left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)} \]
  7. Step-by-step derivation
    1. lower-+.f32N/A

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(1 + \color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}\right) \]
    3. lower-PI.f3225.0

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

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

Alternative 9: 25.1% accurate, 4.3× speedup?

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

\\
\left(-s\right) \cdot \mathsf{log1p}\left(\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 \color{blue}{\log \left(1 + \frac{\mathsf{PI}\left(\right)}{s}\right)} \]
  7. Step-by-step derivation
    1. lower-log1p.f32N/A

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}\right) \]
    3. lower-PI.f3225.0

      \[\leadsto \left(-s\right) \cdot \mathsf{log1p}\left(\frac{\color{blue}{\pi}}{s}\right) \]
  8. Applied rewrites25.0%

    \[\leadsto \left(-s\right) \cdot \color{blue}{\mathsf{log1p}\left(\frac{\pi}{s}\right)} \]
  9. Add Preprocessing

Alternative 10: 11.6% accurate, 23.2× speedup?

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

\\
\mathsf{fma}\left(\pi, 0.25, \pi \cdot \left(u \cdot -0.5\right)\right) \cdot -4
\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 \mathsf{fma}\left(\pi, 0.25, \pi \cdot \left(u \cdot -0.5\right)\right) \cdot -4 \]
  7. Add Preprocessing

Alternative 11: 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 12: 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 13: 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. 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)} \]
  4. 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)} \]
  5. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

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

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

      \[\leadsto \left(-1 \cdot s\right) \cdot \color{blue}{0} \]
    7. lower-*.f32N/A

      \[\leadsto \color{blue}{\left(-1 \cdot s\right) \cdot 0} \]
    8. mul-1-negN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(s\right)\right)} \cdot 0 \]
    9. lower-neg.f329.9

      \[\leadsto \color{blue}{\left(-s\right)} \cdot 0 \]
  6. Applied rewrites9.9%

    \[\leadsto \color{blue}{\left(-s\right) \cdot 0} \]
  7. Step-by-step derivation
    1. lift-neg.f32N/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(s\right)\right)} \cdot 0 \]
    2. mul0-rgt9.9

      \[\leadsto \color{blue}{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))))