Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 10.5s
Alternatives: 11
Speedup: N/A×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

\\
s \cdot \left(-\log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)\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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

Alternative 2: 13.3% accurate, 1.8× speedup?

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

\\
\log \left({\left(e^{s}\right)}^{\left(\frac{\pi \cdot \left(-1 + u \cdot 2\right)}{s}\right)}\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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\left(\pi \cdot u\right) \cdot -0.5 + \pi \cdot 0.25}{s}}\right)}^{3}}\right) \]
    3. associate-*l*11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\pi \cdot \left(u \cdot -0.5\right) + \color{blue}{0.25 \cdot \pi}}{s}}\right)}^{3}\right) \]
    5. fma-def11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \color{blue}{\pi \cdot 0.25}\right)}{s}}\right)}^{3}\right) \]
  8. Applied egg-rr11.6%

    \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}}\right) \]
  9. Step-by-step derivation
    1. log1p-expm1-u11.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    2. log1p-udef11.6%

      \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    3. distribute-lft-neg-in11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \color{blue}{\left(\left(-4\right) \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)}\right)\right) \]
    4. metadata-eval11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(\color{blue}{-4} \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right) \]
    5. unpow311.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}\right)\right)\right) \]
    6. add-cube-cbrt11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)\right)\right) \]
  10. Applied egg-rr11.6%

    \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)\right)} \]
  11. Step-by-step derivation
    1. *-un-lft-identity11.6%

      \[\leadsto \log \color{blue}{\left(1 \cdot \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)\right)\right)} \]
  12. Applied egg-rr11.6%

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

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

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

Alternative 3: 11.7% accurate, 1.8× speedup?

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

\\
\log \left(1 + \mathsf{expm1}\left(2 \cdot \left(u \cdot \pi\right) - \pi\right)\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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\left(\pi \cdot u\right) \cdot -0.5 + \pi \cdot 0.25}{s}}\right)}^{3}}\right) \]
    3. associate-*l*11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\pi \cdot \left(u \cdot -0.5\right) + \color{blue}{0.25 \cdot \pi}}{s}}\right)}^{3}\right) \]
    5. fma-def11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \color{blue}{\pi \cdot 0.25}\right)}{s}}\right)}^{3}\right) \]
  8. Applied egg-rr11.6%

    \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}}\right) \]
  9. Step-by-step derivation
    1. log1p-expm1-u11.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    2. log1p-udef11.6%

      \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    3. distribute-lft-neg-in11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \color{blue}{\left(\left(-4\right) \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)}\right)\right) \]
    4. metadata-eval11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(\color{blue}{-4} \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right) \]
    5. unpow311.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}\right)\right)\right) \]
    6. add-cube-cbrt11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)\right)\right) \]
  10. Applied egg-rr11.6%

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

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

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(2 \cdot \left(u \cdot \pi\right) - \pi\right)\right) \]

Alternative 4: 11.7% accurate, 2.3× speedup?

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

\\
\log \left(1 + \mathsf{expm1}\left(s \cdot \frac{\pi \cdot \left(-1 + u \cdot 2\right)}{s}\right)\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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\left(\pi \cdot u\right) \cdot -0.5 + \pi \cdot 0.25}{s}}\right)}^{3}}\right) \]
    3. associate-*l*11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\pi \cdot \left(u \cdot -0.5\right) + \color{blue}{0.25 \cdot \pi}}{s}}\right)}^{3}\right) \]
    5. fma-def11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \color{blue}{\pi \cdot 0.25}\right)}{s}}\right)}^{3}\right) \]
  8. Applied egg-rr11.6%

    \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}}\right) \]
  9. Step-by-step derivation
    1. log1p-expm1-u11.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    2. log1p-udef11.6%

      \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    3. distribute-lft-neg-in11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \color{blue}{\left(\left(-4\right) \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)}\right)\right) \]
    4. metadata-eval11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(\color{blue}{-4} \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right) \]
    5. unpow311.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}\right)\right)\right) \]
    6. add-cube-cbrt11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)\right)\right) \]
  10. Applied egg-rr11.6%

    \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)\right)} \]
  11. Step-by-step derivation
    1. pow111.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{{\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)}^{1}}\right)\right) \]
  12. Applied egg-rr11.6%

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{{\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)}^{1}}\right)\right) \]
  13. Simplified11.6%

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{s \cdot \frac{\pi \cdot \left(-1 + u \cdot 2\right)}{s}}\right)\right) \]
  14. Final simplification11.6%

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \frac{\pi \cdot \left(-1 + u \cdot 2\right)}{s}\right)\right) \]

Alternative 5: 11.7% accurate, 2.4× speedup?

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

\\
\log \left(1 + \mathsf{expm1}\left(\pi \cdot \left(-1 + u \cdot 2\right)\right)\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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\left(\pi \cdot u\right) \cdot -0.5 + \pi \cdot 0.25}{s}}\right)}^{3}}\right) \]
    3. associate-*l*11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\pi \cdot \left(u \cdot -0.5\right) + \color{blue}{0.25 \cdot \pi}}{s}}\right)}^{3}\right) \]
    5. fma-def11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \color{blue}{\pi \cdot 0.25}\right)}{s}}\right)}^{3}\right) \]
  8. Applied egg-rr11.6%

    \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}}\right) \]
  9. Step-by-step derivation
    1. log1p-expm1-u11.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    2. log1p-udef11.6%

      \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    3. distribute-lft-neg-in11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \color{blue}{\left(\left(-4\right) \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)}\right)\right) \]
    4. metadata-eval11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(\color{blue}{-4} \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right) \]
    5. unpow311.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}\right)\right)\right) \]
    6. add-cube-cbrt11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(s \cdot \left(-4 \cdot \color{blue}{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)\right)\right) \]
  10. Applied egg-rr11.6%

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

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{-4 \cdot \left(-0.5 \cdot \left(u \cdot \pi\right) + 0.25 \cdot \pi\right)}\right)\right) \]
  12. Step-by-step derivation
    1. +-commutative11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(-4 \cdot \color{blue}{\left(0.25 \cdot \pi + -0.5 \cdot \left(u \cdot \pi\right)\right)}\right)\right) \]
    2. distribute-lft-in11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{-4 \cdot \left(0.25 \cdot \pi\right) + -4 \cdot \left(-0.5 \cdot \left(u \cdot \pi\right)\right)}\right)\right) \]
    3. associate-*r*11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{\left(-4 \cdot 0.25\right) \cdot \pi} + -4 \cdot \left(-0.5 \cdot \left(u \cdot \pi\right)\right)\right)\right) \]
    4. metadata-eval11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{-1} \cdot \pi + -4 \cdot \left(-0.5 \cdot \left(u \cdot \pi\right)\right)\right)\right) \]
    5. associate-*r*11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(-1 \cdot \pi + \color{blue}{\left(-4 \cdot -0.5\right) \cdot \left(u \cdot \pi\right)}\right)\right) \]
    6. metadata-eval11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(-1 \cdot \pi + \color{blue}{2} \cdot \left(u \cdot \pi\right)\right)\right) \]
    7. associate-*r*11.6%

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

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{\pi \cdot \left(-1 + 2 \cdot u\right)}\right)\right) \]
    9. *-commutative11.6%

      \[\leadsto \log \left(1 + \mathsf{expm1}\left(\pi \cdot \left(-1 + \color{blue}{u \cdot 2}\right)\right)\right) \]
  13. Simplified11.6%

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{\pi \cdot \left(-1 + u \cdot 2\right)}\right)\right) \]
  14. Final simplification11.6%

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\pi \cdot \left(-1 + u \cdot 2\right)\right)\right) \]

Alternative 6: 11.7% accurate, 3.4× speedup?

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

\\
s \cdot \left(4 \cdot \frac{\left(u \cdot \pi\right) \cdot \left(--0.5\right) - \pi \cdot 0.25}{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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto s \cdot \left(4 \cdot \frac{\left(u \cdot \pi\right) \cdot \left(--0.5\right) - \pi \cdot 0.25}{s}\right) \]

Alternative 7: 11.7% accurate, 3.6× speedup?

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

\\
2 \cdot \left(u \cdot \pi\right) - \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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto 2 \cdot \left(u \cdot \pi\right) - \pi \]

Alternative 8: 11.7% accurate, 6.6× speedup?

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

\\
s \cdot \frac{\pi \cdot \left(-1 + u \cdot 2\right)}{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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\left(\pi \cdot u\right) \cdot -0.5 + \pi \cdot 0.25}{s}}\right)}^{3}}\right) \]
    3. associate-*l*11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\pi \cdot \left(u \cdot -0.5\right) + \color{blue}{0.25 \cdot \pi}}{s}}\right)}^{3}\right) \]
    5. fma-def11.6%

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

      \[\leadsto s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \color{blue}{\pi \cdot 0.25}\right)}{s}}\right)}^{3}\right) \]
  8. Applied egg-rr11.6%

    \[\leadsto s \cdot \left(-4 \cdot \color{blue}{{\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}}\right) \]
  9. Step-by-step derivation
    1. expm1-log1p-u0.9%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)\right)} \]
    2. expm1-udef0.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(s \cdot \left(-4 \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)} - 1} \]
    3. distribute-lft-neg-in0.9%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \color{blue}{\left(\left(-4\right) \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)}\right)} - 1 \]
    4. metadata-eval0.9%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \left(\color{blue}{-4} \cdot {\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}^{3}\right)\right)} - 1 \]
    5. unpow30.9%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \left(-4 \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)}\right)\right)} - 1 \]
    6. add-cube-cbrt0.9%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \left(-4 \cdot \color{blue}{\frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}}\right)\right)} - 1 \]
  10. Applied egg-rr0.9%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)} - 1} \]
  11. Step-by-step derivation
    1. expm1-def0.9%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot \left(-4 \cdot \frac{\mathsf{fma}\left(\pi, u \cdot -0.5, \pi \cdot 0.25\right)}{s}\right)\right)\right)} \]
    2. expm1-log1p11.6%

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

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

    \[\leadsto \color{blue}{s \cdot \frac{\pi \cdot \left(u \cdot 2 + -1\right)}{s}} \]
  13. Final simplification11.6%

    \[\leadsto s \cdot \frac{\pi \cdot \left(-1 + u \cdot 2\right)}{s} \]

Alternative 9: 11.7% accurate, 6.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 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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\pi \cdot \left(2 \cdot u + -1\right)} \]
    10. *-commutative11.6%

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

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

    \[\leadsto \pi \cdot \left(-1 + u \cdot 2\right) \]

Alternative 10: 11.5% accurate, 7.2× 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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

    \[\leadsto -\pi \]

Alternative 11: 4.6% accurate, 7.3× speedup?

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

\\
\pi
\end{array}
Derivation
  1. Initial program 98.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. Step-by-step derivation
    1. distribute-lft-neg-out98.9%

      \[\leadsto \color{blue}{-s \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. distribute-rgt-neg-in98.9%

      \[\leadsto \color{blue}{s \cdot \left(-\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)\right)} \]
    3. sub-neg98.9%

      \[\leadsto s \cdot \left(-\log \color{blue}{\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}}}} + \left(-1\right)\right)}\right) \]
  3. Simplified98.9%

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

    \[\leadsto s \cdot \left(-\color{blue}{\frac{\pi}{s}}\right) \]
  5. Step-by-step derivation
    1. expm1-log1p-u-0.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot \left(-\frac{\pi}{s}\right)\right)\right)} \]
    2. expm1-udef-0.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(s \cdot \left(-\frac{\pi}{s}\right)\right)} - 1} \]
    3. add-sqr-sqrt-0.0%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \color{blue}{\left(\sqrt{-\frac{\pi}{s}} \cdot \sqrt{-\frac{\pi}{s}}\right)}\right)} - 1 \]
    4. sqrt-unprod3.5%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \color{blue}{\sqrt{\left(-\frac{\pi}{s}\right) \cdot \left(-\frac{\pi}{s}\right)}}\right)} - 1 \]
    5. sqr-neg3.5%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \sqrt{\color{blue}{\frac{\pi}{s} \cdot \frac{\pi}{s}}}\right)} - 1 \]
    6. sqrt-unprod4.8%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \color{blue}{\left(\sqrt{\frac{\pi}{s}} \cdot \sqrt{\frac{\pi}{s}}\right)}\right)} - 1 \]
    7. add-sqr-sqrt4.8%

      \[\leadsto e^{\mathsf{log1p}\left(s \cdot \color{blue}{\frac{\pi}{s}}\right)} - 1 \]
  6. Applied egg-rr4.8%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(s \cdot \frac{\pi}{s}\right)} - 1} \]
  7. Step-by-step derivation
    1. expm1-def4.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot \frac{\pi}{s}\right)\right)} \]
    2. expm1-log1p4.8%

      \[\leadsto \color{blue}{s \cdot \frac{\pi}{s}} \]
    3. associate-*r/4.8%

      \[\leadsto \color{blue}{\frac{s \cdot \pi}{s}} \]
    4. associate-*l/4.8%

      \[\leadsto \color{blue}{\frac{s}{s} \cdot \pi} \]
    5. *-inverses4.8%

      \[\leadsto \color{blue}{1} \cdot \pi \]
    6. *-lft-identity4.8%

      \[\leadsto \color{blue}{\pi} \]
  8. Simplified4.8%

    \[\leadsto \color{blue}{\pi} \]
  9. Final simplification4.8%

    \[\leadsto \pi \]

Reproduce

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