Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 13.4s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 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, 1.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \log \left(\frac{1}{\left(\frac{1}{1 + e^{\frac{\pi}{s}}} + \frac{u}{1 + e^{-1 \cdot \frac{\pi}{s}}}\right) - \frac{u}{1 + e^{\frac{\pi}{s}}}} - 1\right)\right)} \]
  5. Step-by-step derivation
    1. mul-1-neg99.0%

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

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

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

    \[\leadsto \left(-s\right) \cdot \log \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) \]
  8. Add Preprocessing

Alternative 2: 98.9% accurate, 1.3× speedup?

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

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

    \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{\frac{\pi}{-s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)} \]
  3. Add Preprocessing
  4. Final simplification99.0%

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

Alternative 3: 25.0% accurate, 3.8× speedup?

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

\\
s \cdot \left(-\log \left(-1 + \left(2 + 4 \cdot \frac{\pi \cdot 0.25}{s}\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.1%

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

    \[\leadsto \left(-s\right) \cdot \log \left(\color{blue}{\left(2 + 4 \cdot \frac{u \cdot \left(-0.25 \cdot \pi - 0.25 \cdot \pi\right) - -0.25 \cdot \pi}{s}\right)} - 1\right) \]
  4. Step-by-step derivation
    1. cancel-sign-sub-inv24.4%

      \[\leadsto \left(-s\right) \cdot \log \left(\left(2 + 4 \cdot \frac{\color{blue}{u \cdot \left(-0.25 \cdot \pi - 0.25 \cdot \pi\right) + \left(--0.25\right) \cdot \pi}}{s}\right) - 1\right) \]
    2. metadata-eval24.4%

      \[\leadsto \left(-s\right) \cdot \log \left(\left(2 + 4 \cdot \frac{u \cdot \left(-0.25 \cdot \pi - 0.25 \cdot \pi\right) + \color{blue}{0.25} \cdot \pi}{s}\right) - 1\right) \]
    3. distribute-rgt-out--24.4%

      \[\leadsto \left(-s\right) \cdot \log \left(\left(2 + 4 \cdot \frac{u \cdot \color{blue}{\left(\pi \cdot \left(-0.25 - 0.25\right)\right)} + 0.25 \cdot \pi}{s}\right) - 1\right) \]
    4. metadata-eval24.4%

      \[\leadsto \left(-s\right) \cdot \log \left(\left(2 + 4 \cdot \frac{u \cdot \left(\pi \cdot \color{blue}{-0.5}\right) + 0.25 \cdot \pi}{s}\right) - 1\right) \]
    5. *-commutative24.4%

      \[\leadsto \left(-s\right) \cdot \log \left(\left(2 + 4 \cdot \frac{u \cdot \left(\pi \cdot -0.5\right) + \color{blue}{\pi \cdot 0.25}}{s}\right) - 1\right) \]
  5. Simplified24.4%

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

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

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

Alternative 4: 14.3% accurate, 27.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;s \leq 2.9999999047965676 \cdot 10^{-20}:\\ \;\;\;\;s \cdot 0\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \left(\pi \cdot \left(u \cdot \left(-0.5 + \frac{0.25}{u}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (if (<= s 2.9999999047965676e-20)
   (* s 0.0)
   (* -4.0 (* PI (* u (+ -0.5 (/ 0.25 u)))))))
float code(float u, float s) {
	float tmp;
	if (s <= 2.9999999047965676e-20f) {
		tmp = s * 0.0f;
	} else {
		tmp = -4.0f * (((float) M_PI) * (u * (-0.5f + (0.25f / u))));
	}
	return tmp;
}
function code(u, s)
	tmp = Float32(0.0)
	if (s <= Float32(2.9999999047965676e-20))
		tmp = Float32(s * Float32(0.0));
	else
		tmp = Float32(Float32(-4.0) * Float32(Float32(pi) * Float32(u * Float32(Float32(-0.5) + Float32(Float32(0.25) / u)))));
	end
	return tmp
end
function tmp_2 = code(u, s)
	tmp = single(0.0);
	if (s <= single(2.9999999047965676e-20))
		tmp = s * single(0.0);
	else
		tmp = single(-4.0) * (single(pi) * (u * (single(-0.5) + (single(0.25) / u))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;s \leq 2.9999999047965676 \cdot 10^{-20}:\\
\;\;\;\;s \cdot 0\\

\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\pi \cdot \left(u \cdot \left(-0.5 + \frac{0.25}{u}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 2.9999999e-20

    1. Initial program 99.3%

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

      \[\leadsto \left(-s\right) \cdot \log \color{blue}{1} \]

    if 2.9999999e-20 < s

    1. Initial program 98.8%

      \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\pi}{s}}} - \frac{1}{1 + e^{\frac{\pi}{s}}}\right) + \frac{1}{1 + e^{\frac{\pi}{s}}}} - 1\right) \]
    2. Simplified98.8%

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

      \[\leadsto \color{blue}{-4 \cdot \left(-0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)\right)} \]
    5. Step-by-step derivation
      1. associate--r+15.8%

        \[\leadsto -4 \cdot \color{blue}{\left(\left(-0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right)} \]
      2. cancel-sign-sub-inv15.8%

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

        \[\leadsto -4 \cdot \left(\left(-0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right) \]
      4. cancel-sign-sub-inv15.8%

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

        \[\leadsto -4 \cdot \left(\left(\color{blue}{\left(-0.25 \cdot u\right) \cdot \pi} + 0.25 \cdot \pi\right) + \left(-0.25\right) \cdot \left(u \cdot \pi\right)\right) \]
      6. distribute-rgt-out15.8%

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

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

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

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

      \[\leadsto \color{blue}{-4 \cdot \left(\pi \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right)} \]
    7. Step-by-step derivation
      1. add-cube-cbrt15.9%

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

        \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
    8. Applied egg-rr15.9%

      \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
    9. Taylor expanded in u around inf 15.8%

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

        \[\leadsto -4 \cdot \left(u \cdot \left(\color{blue}{\pi \cdot -0.5} + 0.25 \cdot \frac{\pi}{u}\right)\right) \]
      2. fma-define15.8%

        \[\leadsto -4 \cdot \left(u \cdot \color{blue}{\mathsf{fma}\left(\pi, -0.5, 0.25 \cdot \frac{\pi}{u}\right)}\right) \]
      3. associate-*r/15.8%

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

        \[\leadsto -4 \cdot \left(u \cdot \mathsf{fma}\left(\pi, -0.5, \frac{\color{blue}{\pi \cdot 0.25}}{u}\right)\right) \]
      5. associate-/l*15.8%

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

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

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

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

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

        \[\leadsto -4 \cdot \left(\left(\pi \cdot -0.5\right) \cdot u + \color{blue}{\frac{0.25 \cdot \pi}{u}} \cdot u\right) \]
      4. *-commutative15.8%

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

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

        \[\leadsto -4 \cdot \color{blue}{\left(u \cdot \left(\pi \cdot -0.5 + \pi \cdot \frac{0.25}{u}\right)\right)} \]
      7. distribute-lft-in15.8%

        \[\leadsto -4 \cdot \left(u \cdot \color{blue}{\left(\pi \cdot \left(-0.5 + \frac{0.25}{u}\right)\right)}\right) \]
      8. *-commutative15.8%

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

        \[\leadsto -4 \cdot \color{blue}{\left(\pi \cdot \left(\left(-0.5 + \frac{0.25}{u}\right) \cdot u\right)\right)} \]
    14. Simplified15.8%

      \[\leadsto -4 \cdot \color{blue}{\left(\pi \cdot \left(\left(-0.5 + \frac{0.25}{u}\right) \cdot u\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 2.9999999047965676 \cdot 10^{-20}:\\ \;\;\;\;s \cdot 0\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \left(\pi \cdot \left(u \cdot \left(-0.5 + \frac{0.25}{u}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 11.6% accurate, 39.4× speedup?

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

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

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(-0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)\right)} \]
  5. Step-by-step derivation
    1. associate--r+11.3%

      \[\leadsto -4 \cdot \color{blue}{\left(\left(-0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right)} \]
    2. cancel-sign-sub-inv11.3%

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

      \[\leadsto -4 \cdot \left(\left(-0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right) \]
    4. cancel-sign-sub-inv11.3%

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

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

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

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

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(\pi \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right)} \]
  7. Step-by-step derivation
    1. add-cube-cbrt11.3%

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

      \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
  8. Applied egg-rr11.3%

    \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
  9. Taylor expanded in u around inf 11.3%

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

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

      \[\leadsto -4 \cdot \left(u \cdot \color{blue}{\mathsf{fma}\left(\pi, -0.5, 0.25 \cdot \frac{\pi}{u}\right)}\right) \]
    3. associate-*r/11.3%

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

      \[\leadsto -4 \cdot \left(u \cdot \mathsf{fma}\left(\pi, -0.5, \frac{\color{blue}{\pi \cdot 0.25}}{u}\right)\right) \]
    5. associate-/l*11.3%

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

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

    \[\leadsto -4 \cdot \color{blue}{\left(u \cdot \left(-0.5 \cdot \pi + 0.25 \cdot \frac{\pi}{u}\right)\right)} \]
  13. Step-by-step derivation
    1. distribute-rgt-in11.3%

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

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

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

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

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

      \[\leadsto -4 \cdot \color{blue}{\left(u \cdot \left(\pi \cdot -0.5 + \pi \cdot \frac{0.25}{u}\right)\right)} \]
    7. distribute-lft-in11.3%

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

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

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

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

    \[\leadsto -4 \cdot \left(\pi \cdot \left(u \cdot \left(-0.5 + \frac{0.25}{u}\right)\right)\right) \]
  16. Add Preprocessing

Alternative 6: 11.6% accurate, 48.1× speedup?

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

\\
u \cdot \left(\pi \cdot 2 - \frac{\pi}{u}\right)
\end{array}
Derivation
  1. Initial program 99.1%

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(-0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)\right)} \]
  5. Step-by-step derivation
    1. associate--r+11.3%

      \[\leadsto -4 \cdot \color{blue}{\left(\left(-0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right)} \]
    2. cancel-sign-sub-inv11.3%

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

      \[\leadsto -4 \cdot \left(\left(-0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right) \]
    4. cancel-sign-sub-inv11.3%

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

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

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

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

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(\pi \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right)} \]
  7. Step-by-step derivation
    1. add-cube-cbrt11.3%

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

      \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
  8. Applied egg-rr11.3%

    \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
  9. Taylor expanded in u around 0 11.3%

    \[\leadsto \color{blue}{-1 \cdot \pi + 2 \cdot \left(u \cdot \pi\right)} \]
  10. Taylor expanded in u around inf 11.3%

    \[\leadsto \color{blue}{u \cdot \left(-1 \cdot \frac{\pi}{u} + 2 \cdot \pi\right)} \]
  11. Step-by-step derivation
    1. +-commutative11.3%

      \[\leadsto u \cdot \color{blue}{\left(2 \cdot \pi + -1 \cdot \frac{\pi}{u}\right)} \]
    2. mul-1-neg11.3%

      \[\leadsto u \cdot \left(2 \cdot \pi + \color{blue}{\left(-\frac{\pi}{u}\right)}\right) \]
    3. unsub-neg11.3%

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

      \[\leadsto u \cdot \left(\color{blue}{\pi \cdot 2} - \frac{\pi}{u}\right) \]
  12. Simplified11.3%

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

Alternative 7: 11.6% accurate, 61.9× speedup?

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

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

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(-0.25 \cdot \left(u \cdot \pi\right) - \left(-0.25 \cdot \pi + 0.25 \cdot \left(u \cdot \pi\right)\right)\right)} \]
  5. Step-by-step derivation
    1. associate--r+11.3%

      \[\leadsto -4 \cdot \color{blue}{\left(\left(-0.25 \cdot \left(u \cdot \pi\right) - -0.25 \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right)} \]
    2. cancel-sign-sub-inv11.3%

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

      \[\leadsto -4 \cdot \left(\left(-0.25 \cdot \left(u \cdot \pi\right) + \color{blue}{0.25} \cdot \pi\right) - 0.25 \cdot \left(u \cdot \pi\right)\right) \]
    4. cancel-sign-sub-inv11.3%

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

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

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

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

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(\pi \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right)} \]
  7. Step-by-step derivation
    1. add-cube-cbrt11.3%

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

      \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
  8. Applied egg-rr11.3%

    \[\leadsto -4 \cdot \left(\color{blue}{{\left(\sqrt[3]{\pi}\right)}^{3}} \cdot \left(-0.25 \cdot u + 0.25\right) + \left(\pi \cdot u\right) \cdot -0.25\right) \]
  9. Taylor expanded in u around 0 11.3%

    \[\leadsto \color{blue}{-1 \cdot \pi + 2 \cdot \left(u \cdot \pi\right)} \]
  10. Step-by-step derivation
    1. associate-*r*11.3%

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

      \[\leadsto \color{blue}{\pi \cdot \left(-1 + 2 \cdot u\right)} \]
  11. Simplified11.3%

    \[\leadsto \color{blue}{\pi \cdot \left(-1 + 2 \cdot u\right)} \]
  12. Final simplification11.3%

    \[\leadsto \pi \cdot \left(-1 + u \cdot 2\right) \]
  13. Add Preprocessing

Alternative 8: 11.4% accurate, 216.5× speedup?

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

\\
-\pi
\end{array}
Derivation
  1. Initial program 99.1%

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

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

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

      \[\leadsto \color{blue}{-\pi} \]
  6. Simplified11.1%

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

Alternative 9: 4.6% accurate, 433.0× speedup?

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

\\
\pi
\end{array}
Derivation
  1. Initial program 99.1%

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

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

      \[\leadsto \color{blue}{\frac{\left(-s\right) \cdot \pi}{s}} \]
    2. add-sqr-sqrt-0.0%

      \[\leadsto \frac{\color{blue}{\left(\sqrt{-s} \cdot \sqrt{-s}\right)} \cdot \pi}{s} \]
    3. sqrt-unprod8.9%

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}} \cdot \pi}{s} \]
    4. sqr-neg8.9%

      \[\leadsto \frac{\sqrt{\color{blue}{s \cdot s}} \cdot \pi}{s} \]
    5. sqrt-unprod4.7%

      \[\leadsto \frac{\color{blue}{\left(\sqrt{s} \cdot \sqrt{s}\right)} \cdot \pi}{s} \]
    6. add-sqr-sqrt4.7%

      \[\leadsto \frac{\color{blue}{s} \cdot \pi}{s} \]
  5. Applied egg-rr4.7%

    \[\leadsto \color{blue}{\frac{s \cdot \pi}{s}} \]
  6. Step-by-step derivation
    1. associate-/l*4.7%

      \[\leadsto \color{blue}{s \cdot \frac{\pi}{s}} \]
  7. Simplified4.7%

    \[\leadsto \color{blue}{s \cdot \frac{\pi}{s}} \]
  8. Taylor expanded in s around 0 4.7%

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

Reproduce

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