Sample trimmed logistic on [-pi, pi]

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

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

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f32N/A

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

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\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) \cdot u} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
    4. lower-fma.f3298.9

      \[\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) \]
  4. Applied rewrites98.9%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.0% accurate, 1.0× speedup?

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

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f32N/A

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

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

      \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\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) \cdot u} + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
    4. lower-fma.f3298.9

      \[\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) \]
  4. Applied rewrites98.9%

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

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

Alternative 3: 97.7% accurate, 1.3× speedup?

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

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

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

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

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

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

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

Alternative 4: 25.0% accurate, 3.6× speedup?

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

\\
\log \left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(0.5 \cdot \pi, u, -0.25 \cdot \pi\right)}{s}, -4, 1\right)\right) \cdot \left(-s\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
  2. 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{1}{2}}} - 1\right) \]
  4. Step-by-step derivation
    1. Applied rewrites10.3%

      \[\leadsto \left(-s\right) \cdot \log \left(\frac{1}{\color{blue}{0.5}} - 1\right) \]
    2. 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)} \]
    3. 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. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \left(\color{blue}{\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} \cdot -4} + 1\right) \]
      3. lower-fma.f32N/A

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \log \color{blue}{\left(\mathsf{fma}\left(\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}, -4, 1\right)\right)} \]
    4. Applied rewrites25.0%

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

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

    Alternative 5: 13.9% accurate, 14.6× speedup?

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(s\right)\right) \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{s}} \]
      2. lower-PI.f3210.7

        \[\leadsto \left(-s\right) \cdot \frac{\color{blue}{\pi}}{s} \]
    5. Applied rewrites10.7%

      \[\leadsto \left(-s\right) \cdot \color{blue}{\frac{\pi}{s}} \]
    6. Step-by-step derivation
      1. --rgt-identityN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(s\right)\right) - 0\right)} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      2. flip--N/A

        \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(s\right)\right) \cdot \left(\mathsf{neg}\left(s\right)\right) - 0 \cdot 0}{\left(\mathsf{neg}\left(s\right)\right) + 0}} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      3. lift-neg.f32N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(s\right)\right)} \cdot \left(\mathsf{neg}\left(s\right)\right) - 0 \cdot 0}{\left(\mathsf{neg}\left(s\right)\right) + 0} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      4. lift-neg.f32N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(s\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(s\right)\right)} - 0 \cdot 0}{\left(\mathsf{neg}\left(s\right)\right) + 0} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      5. sqr-negN/A

        \[\leadsto \frac{\color{blue}{s \cdot s} - 0 \cdot 0}{\left(\mathsf{neg}\left(s\right)\right) + 0} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      6. lift-*.f32N/A

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

        \[\leadsto \frac{s \cdot s - \color{blue}{0}}{\left(\mathsf{neg}\left(s\right)\right) + 0} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      8. --rgt-identityN/A

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

        \[\leadsto \frac{s \cdot s}{\left(\mathsf{neg}\left(s\right)\right) + \color{blue}{\left(\mathsf{neg}\left(0\right)\right)}} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      10. sub-negN/A

        \[\leadsto \frac{s \cdot s}{\color{blue}{\left(\mathsf{neg}\left(s\right)\right) - 0}} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      11. --rgt-identityN/A

        \[\leadsto \frac{s \cdot s}{\color{blue}{\mathsf{neg}\left(s\right)}} \cdot \frac{\mathsf{PI}\left(\right)}{s} \]
      12. lower-/.f3213.3

        \[\leadsto \color{blue}{\frac{s \cdot s}{-s}} \cdot \frac{\pi}{s} \]
    7. Applied rewrites13.3%

      \[\leadsto \color{blue}{\frac{s \cdot s}{-s}} \cdot \frac{\pi}{s} \]
    8. Final simplification13.3%

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

    Alternative 6: 11.6% accurate, 20.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto u \cdot \color{blue}{\left(-1 \cdot \frac{\mathsf{PI}\left(\right)}{u} + 2 \cdot \mathsf{PI}\left(\right)\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites10.9%

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

      Alternative 7: 11.5% accurate, 23.2× speedup?

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

        \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-neg.f32N/A

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{0 + {\left(\mathsf{neg}\left(s\right)\right)}^{3}}{0 + \left(\color{blue}{\left(\mathsf{neg}\left(s\right)\right) \cdot \left(\mathsf{neg}\left(s\right)\right)} - 0 \cdot \left(\mathsf{neg}\left(s\right)\right)\right)} \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
        14. lower-*.f3236.9

          \[\leadsto \frac{0 + {\left(-s\right)}^{3}}{0 + \left(\left(-s\right) \cdot \left(-s\right) - \color{blue}{0 \cdot \left(-s\right)}\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) \]
      4. Applied rewrites36.9%

        \[\leadsto \color{blue}{\frac{0 + {\left(-s\right)}^{3}}{0 + \left(\left(-s\right) \cdot \left(-s\right) - 0 \cdot \left(-s\right)\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) \]
      5. 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)} \]
      6. 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. *-commutativeN/A

          \[\leadsto \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) \cdot 4 \]
        5. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

      Alternative 8: 11.5% accurate, 23.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

      Alternative 9: 11.5% accurate, 42.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \mathsf{PI}\left(\right) + \color{blue}{2 \cdot \left(u \cdot \mathsf{PI}\left(\right)\right)} \]
      7. Step-by-step derivation
        1. Applied rewrites10.9%

          \[\leadsto \pi \cdot \color{blue}{\mathsf{fma}\left(2, u, -1\right)} \]
        2. Final simplification10.9%

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

        Alternative 10: 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.9%

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

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

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

        Reproduce

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