Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 99.0%
Time: 15.2s
Alternatives: 10
Speedup: 0.3×

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{\mathsf{PI}\left(\right)}{s}}}\\ \left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{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)))))
\begin{array}{l}

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 98.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\\ \left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{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)))))
\begin{array}{l}

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

Alternative 1: 99.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\ t_1 := \mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right) \cdot 2\\ \left(-s\right) \cdot \log \left(\frac{2 - t\_1}{t\_1}\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (exp (- (log1p (exp (/ (PI) s))))))
        (t_1
         (* (fma (- (exp (- (log1p (exp (/ (- (PI)) s))))) t_0) u t_0) 2.0)))
   (* (- s) (log (/ (- 2.0 t_1) t_1)))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\
t_1 := \mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right) \cdot 2\\
\left(-s\right) \cdot \log \left(\frac{2 - t\_1}{t\_1}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

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

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

      \[\leadsto \left(-s\right) \cdot \log \color{blue}{\left(\frac{1 \cdot 2 - \left(u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) \cdot 2}{\left(u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) \cdot 2}\right)} \]
  4. Applied rewrites99.1%

    \[\leadsto \left(-s\right) \cdot \log \color{blue}{\left(\frac{2 - \mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}, u, e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\right) \cdot 2}{\mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}, u, e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\right) \cdot 2}\right)} \]
  5. Add Preprocessing

Alternative 2: 98.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\\ \left(-s\right) \cdot \log \left(\mathsf{expm1}\left(-\log \left(\mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - t\_0, u, t\_0\right)\right)\right)\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (exp (- (log1p (exp (/ (PI) s)))))))
   (*
    (- s)
    (log
     (expm1
      (- (log (fma (- (exp (- (log1p (exp (/ (- (PI)) s))))) t_0) u t_0))))))))
\begin{array}{l}

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

    \[\left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\frac{1}{1 + e^{\frac{-\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) + \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}} - 1\right) \]
  2. Add Preprocessing
  3. Applied rewrites99.0%

    \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\mathsf{expm1}\left(-\log \left(\mathsf{fma}\left(e^{-\mathsf{log1p}\left(e^{\frac{-\mathsf{PI}\left(\right)}{s}}\right)} - e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}, u, e^{-\mathsf{log1p}\left(e^{\frac{\mathsf{PI}\left(\right)}{s}}\right)}\right)\right)\right)\right)} \]
  4. Add Preprocessing

Alternative 3: 98.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{\mathsf{PI}\left(\right)}{s}}\\ \left(-s\right) \cdot \log \left(\frac{1}{u \cdot \left(\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} - -1} - \frac{1}{t\_0 - -1}\right) - \frac{-1}{\mathsf{fma}\left(t\_0, u, u\right)}\right)} - 1\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (exp (/ (PI) s))))
   (*
    (- s)
    (log
     (-
      (/
       1.0
       (*
        u
        (-
         (- (/ 1.0 (- (exp (/ (- (PI)) s)) -1.0)) (/ 1.0 (- t_0 -1.0)))
         (/ -1.0 (fma t_0 u u)))))
      1.0)))))
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

Alternative 4: 98.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} - -1}\\ \left(-s\right) \cdot \log \left(\frac{1}{\mathsf{fma}\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} - -1} - t\_0, u, t\_0\right)} - 1\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (/ 1.0 (- (exp (/ (PI) s)) -1.0))))
   (*
    (- s)
    (log
     (-
      (/ 1.0 (fma (- (/ 1.0 (- (exp (/ (- (PI)) s)) -1.0)) t_0) u t_0))
      1.0)))))
\begin{array}{l}

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

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

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

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

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

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

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

Alternative 5: 97.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(\frac{1}{\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} - -1} - \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} - -1}\right) \cdot u} - 1\right) \end{array} \]
(FPCore (u s)
 :precision binary32
 (*
  (- s)
  (log
   (-
    (/
     1.0
     (*
      (-
       (/ 1.0 (- (exp (/ (- (PI)) s)) -1.0))
       (/ 1.0 (- (exp (/ (PI) s)) -1.0)))
      u))
    1.0))))
\begin{array}{l}

\\
\left(-s\right) \cdot \log \left(\frac{1}{\left(\frac{1}{e^{\frac{-\mathsf{PI}\left(\right)}{s}} - -1} - \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} - -1}\right) \cdot u} - 1\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

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

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

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

Alternative 6: 25.0% accurate, 3.9× speedup?

\[\begin{array}{l} \\ \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{-0.25 \cdot \mathsf{PI}\left(\right)}{s}, -4, 1\right)\right) \end{array} \]
(FPCore (u s)
 :precision binary32
 (* (- s) (log (fma (/ (* -0.25 (PI)) s) -4.0 1.0))))
\begin{array}{l}

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

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

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

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

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

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

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

    \[\leadsto \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{\frac{-1}{4} \cdot \mathsf{PI}\left(\right)}{s}, -4, 1\right)\right) \]
  7. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{\frac{-1}{4} \cdot \mathsf{PI}\left(\right)}{s}, -4, 1\right)\right) \]
    2. lower-PI.f3225.2

      \[\leadsto \left(-s\right) \cdot \log \left(\mathsf{fma}\left(\frac{-0.25 \cdot \mathsf{PI}\left(\right)}{s}, -4, 1\right)\right) \]
  8. Applied rewrites25.2%

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

Alternative 7: 11.6% accurate, 20.4× speedup?

\[\begin{array}{l} \\ u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), \frac{-\mathsf{PI}\left(\right)}{u}\right) \end{array} \]
(FPCore (u s) :precision binary32 (* u (fma 2.0 (PI) (/ (- (PI)) u))))
\begin{array}{l}

\\
u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), \frac{-\mathsf{PI}\left(\right)}{u}\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

      \[\leadsto \left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{4} \]
  5. Applied rewrites11.1%

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

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

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

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

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

      \[\leadsto u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), -1 \cdot \frac{\mathsf{PI}\left(\right)}{u}\right) \]
    5. associate-*r/N/A

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

      \[\leadsto u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), \frac{-1 \cdot \mathsf{PI}\left(\right)}{u}\right) \]
    7. mul-1-negN/A

      \[\leadsto u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), \frac{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)}{u}\right) \]
    8. lower-neg.f32N/A

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

      \[\leadsto u \cdot \mathsf{fma}\left(2, \mathsf{PI}\left(\right), \frac{-\mathsf{PI}\left(\right)}{u}\right) \]
  8. Applied rewrites11.1%

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

Alternative 8: 11.6% accurate, 23.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, u, -0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot 4 \end{array} \]
(FPCore (u s) :precision binary32 (* (fma (* (PI) 0.5) u (* -0.25 (PI))) 4.0))
\begin{array}{l}

\\
\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.5, u, -0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot 4
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

      \[\leadsto \left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{4} \]
  5. Applied rewrites11.1%

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

Alternative 9: 11.6% accurate, 36.4× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(2, u \cdot \mathsf{PI}\left(\right), -\mathsf{PI}\left(\right)\right) \end{array} \]
(FPCore (u s) :precision binary32 (fma 2.0 (* u (PI)) (- (PI))))
\begin{array}{l}

\\
\mathsf{fma}\left(2, u \cdot \mathsf{PI}\left(\right), -\mathsf{PI}\left(\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

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

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

      \[\leadsto \left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{4} \]
  5. Applied rewrites11.1%

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(2, u \cdot \mathsf{PI}\left(\right), -1 \cdot \mathsf{PI}\left(\right)\right) \]
    5. mul-1-negN/A

      \[\leadsto \mathsf{fma}\left(2, u \cdot \mathsf{PI}\left(\right), \mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \]
    6. lower-neg.f32N/A

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

      \[\leadsto \mathsf{fma}\left(2, u \cdot \mathsf{PI}\left(\right), -\mathsf{PI}\left(\right)\right) \]
  8. Applied rewrites11.1%

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

Alternative 10: 11.3% accurate, 170.0× speedup?

\[\begin{array}{l} \\ -\mathsf{PI}\left(\right) \end{array} \]
(FPCore (u s) :precision binary32 (- (PI)))
\begin{array}{l}

\\
-\mathsf{PI}\left(\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

    \[\leadsto \color{blue}{-1 \cdot \mathsf{PI}\left(\right)} \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(\mathsf{PI}\left(\right)\right) \]
    2. lower-neg.f32N/A

      \[\leadsto -\mathsf{PI}\left(\right) \]
    3. lower-PI.f3210.8

      \[\leadsto -\mathsf{PI}\left(\right) \]
  5. Applied rewrites10.8%

    \[\leadsto \color{blue}{-\mathsf{PI}\left(\right)} \]
  6. Add Preprocessing

Reproduce

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