Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 98.9% → 98.9%
Time: 17.1s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right) \land \left(0 \leq s \land s \leq 1.0651631\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{1 + e^{\frac{\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 7 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: 98.9% accurate, 1.0× speedup?

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

\\
\log \left(\frac{1}{\frac{1}{e^{\frac{1}{\frac{s}{\mathsf{PI}\left(\right)}}} + 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) \cdot \left(-s\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. Step-by-step derivation
    1. lift-/.f32N/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^{\color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}}}} - 1\right) \]
    2. clear-numN/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^{\color{blue}{\frac{1}{\frac{s}{\mathsf{PI}\left(\right)}}}}}} - 1\right) \]
    3. lower-/.f32N/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^{\color{blue}{\frac{1}{\frac{s}{\mathsf{PI}\left(\right)}}}}}} - 1\right) \]
    4. lower-/.f3299.0

      \[\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{1}{\color{blue}{\frac{s}{\mathsf{PI}\left(\right)}}}}}} - 1\right) \]
  4. Applied rewrites99.0%

    \[\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^{\color{blue}{\frac{1}{\frac{s}{\mathsf{PI}\left(\right)}}}}}} - 1\right) \]
  5. Final simplification99.0%

    \[\leadsto \log \left(\frac{1}{\frac{1}{e^{\frac{1}{\frac{s}{\mathsf{PI}\left(\right)}}} + 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) \cdot \left(-s\right) \]
  6. Add Preprocessing

Alternative 2: 98.9% accurate, 1.0× speedup?

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

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

    \[\leadsto \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 + \frac{1}{e^{\frac{\mathsf{PI}\left(\right)}{s}} + 1}} - 1\right) \cdot \left(-s\right) \]
  4. Add Preprocessing

Alternative 3: 97.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \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) \cdot \left(-s\right) \end{array} \]
(FPCore (u s)
 :precision binary32
 (*
  (log
   (-
    (/
     1.0
     (*
      (- (/ 1.0 (+ (exp (/ (- (PI)) s)) 1.0)) (/ 1.0 (+ (exp (/ (PI) s)) 1.0)))
      u))
    1.0))
  (- s)))
\begin{array}{l}

\\
\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) \cdot \left(-s\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}{\color{blue}{\left(\frac{1}{1 + e^{-1 \cdot \frac{\mathsf{PI}\left(\right)}{s}}} - \frac{1}{1 + e^{\frac{\mathsf{PI}\left(\right)}{s}}}\right) \cdot u}} - 1\right) \]
    2. lower-*.f32N/A

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

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

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

Alternative 4: 2.8% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\ \frac{\mathsf{fma}\left({t\_0}^{2}, u \cdot u, \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.0625\right) \cdot \frac{-4}{s}}{\mathsf{fma}\left(t\_0, u, 0.25 \cdot \mathsf{PI}\left(\right)\right)} \cdot \left(-s\right) \end{array} \end{array} \]
(FPCore (u s)
 :precision binary32
 (let* ((t_0 (* 0.5 (PI))))
   (*
    (/
     (* (fma (pow t_0 2.0) (* u u) (* (* (PI) (PI)) -0.0625)) (/ -4.0 s))
     (fma t_0 u (* 0.25 (PI))))
    (- s))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\
\frac{\mathsf{fma}\left({t\_0}^{2}, u \cdot u, \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.0625\right) \cdot \frac{-4}{s}}{\mathsf{fma}\left(t\_0, u, 0.25 \cdot \mathsf{PI}\left(\right)\right)} \cdot \left(-s\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 s around inf

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

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

      \[\leadsto \left(-s\right) \cdot \frac{\color{blue}{\left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot -4}}{s} \]
    3. associate-/l*N/A

      \[\leadsto \left(-s\right) \cdot \color{blue}{\left(\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 \frac{-4}{s}\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \left(-s\right) \cdot \color{blue}{\left(\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 \frac{-4}{s}\right)} \]
  5. Applied rewrites11.4%

    \[\leadsto \left(-s\right) \cdot \color{blue}{\left(\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), 0.5, -0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{-4}{s}\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites11.4%

      \[\leadsto \left(-s\right) \cdot \frac{\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right) \cdot u, -0.25 \cdot \mathsf{PI}\left(\right)\right)}{\color{blue}{s \cdot -0.25}} \]
    2. Step-by-step derivation
      1. Applied rewrites9.1%

        \[\leadsto \left(-s\right) \cdot \frac{\frac{-4}{s} \cdot \left({\left(\left(\mathsf{PI}\left(\right) \cdot u\right) \cdot 0.5\right)}^{2} - 0.0625 \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)}{\color{blue}{\mathsf{fma}\left(0.5 \cdot \mathsf{PI}\left(\right), u, 0.25 \cdot \mathsf{PI}\left(\right)\right)}} \]
      2. Step-by-step derivation
        1. Applied rewrites2.8%

          \[\leadsto \left(-s\right) \cdot \frac{\frac{-4}{s} \cdot \mathsf{fma}\left({\left(0.5 \cdot \mathsf{PI}\left(\right)\right)}^{2}, u \cdot u, -0.0625 \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)}{\mathsf{fma}\left(0.5 \cdot \color{blue}{\mathsf{PI}\left(\right)}, u, 0.25 \cdot \mathsf{PI}\left(\right)\right)} \]
        2. Final simplification2.8%

          \[\leadsto \frac{\mathsf{fma}\left({\left(0.5 \cdot \mathsf{PI}\left(\right)\right)}^{2}, u \cdot u, \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.0625\right) \cdot \frac{-4}{s}}{\mathsf{fma}\left(0.5 \cdot \mathsf{PI}\left(\right), u, 0.25 \cdot \mathsf{PI}\left(\right)\right)} \cdot \left(-s\right) \]
        3. Add Preprocessing

        Alternative 5: 11.5% accurate, 21.3× speedup?

        \[\begin{array}{l} \\ 4 \cdot \left(-0.25 \cdot \mathsf{PI}\left(\right) + \left(\mathsf{PI}\left(\right) \cdot u\right) \cdot 0.5\right) \end{array} \]
        (FPCore (u s)
         :precision binary32
         (* 4.0 (+ (* -0.25 (PI)) (* (* (PI) u) 0.5))))
        \begin{array}{l}
        
        \\
        4 \cdot \left(-0.25 \cdot \mathsf{PI}\left(\right) + \left(\mathsf{PI}\left(\right) \cdot u\right) \cdot 0.5\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 \color{blue}{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)} \]
          2. lower-neg.f32N/A

            \[\leadsto \color{blue}{-\mathsf{PI}\left(\right)} \]
          3. lower-PI.f3211.4

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

          \[\leadsto \color{blue}{-\mathsf{PI}\left(\right)} \]
        6. 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)} \]
        7. Step-by-step derivation
          1. *-commutativeN/A

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

            \[\leadsto \color{blue}{\left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot 4} \]
          3. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\mathsf{fma}\left(0.5, u, -0.25\right)}\right) \cdot 4 \]
        8. Applied rewrites11.4%

          \[\leadsto \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right) \cdot 4} \]
        9. Step-by-step derivation
          1. Applied rewrites11.6%

            \[\leadsto \left(\left(\mathsf{PI}\left(\right) \cdot u\right) \cdot 0.5 + -0.25 \cdot \mathsf{PI}\left(\right)\right) \cdot 4 \]
          2. Final simplification11.6%

            \[\leadsto 4 \cdot \left(-0.25 \cdot \mathsf{PI}\left(\right) + \left(\mathsf{PI}\left(\right) \cdot u\right) \cdot 0.5\right) \]
          3. Add Preprocessing

          Alternative 6: 11.5% accurate, 26.8× speedup?

          \[\begin{array}{l} \\ \left(\left(0.5 \cdot u + -0.25\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 4 \end{array} \]
          (FPCore (u s) :precision binary32 (* (* (+ (* 0.5 u) -0.25) (PI)) 4.0))
          \begin{array}{l}
          
          \\
          \left(\left(0.5 \cdot u + -0.25\right) \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 u around 0

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

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

              \[\leadsto \color{blue}{-\mathsf{PI}\left(\right)} \]
            3. lower-PI.f3211.4

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

            \[\leadsto \color{blue}{-\mathsf{PI}\left(\right)} \]
          6. 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)} \]
          7. Step-by-step derivation
            1. *-commutativeN/A

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

              \[\leadsto \color{blue}{\left(u \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right) - \frac{-1}{4} \cdot \mathsf{PI}\left(\right)\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) \cdot 4} \]
            3. cancel-sign-sub-invN/A

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\mathsf{fma}\left(0.5, u, -0.25\right)}\right) \cdot 4 \]
          8. Applied rewrites11.4%

            \[\leadsto \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.5, u, -0.25\right)\right) \cdot 4} \]
          9. Step-by-step derivation
            1. Applied rewrites11.6%

              \[\leadsto \left(\mathsf{PI}\left(\right) \cdot \left(0.5 \cdot u + -0.25\right)\right) \cdot 4 \]
            2. Final simplification11.6%

              \[\leadsto \left(\left(0.5 \cdot u + -0.25\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 4 \]
            3. Add Preprocessing

            Alternative 7: 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 \color{blue}{\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)} \]
              2. lower-neg.f32N/A

                \[\leadsto \color{blue}{-\mathsf{PI}\left(\right)} \]
              3. lower-PI.f3211.4

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

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

            Reproduce

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