Sample trimmed logistic on [-pi, pi]

Percentage Accurate: 99.0% → 99.0%
Time: 15.9s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

Initial Program: 99.0% 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, 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}
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. Add Preprocessing

Alternative 2: 97.7% 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}{\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.0%

    \[\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. Add Preprocessing

Alternative 3: 25.6% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
\left(-s\right) \cdot \log \left(\mathsf{fma}\left(\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), -0.5, 0.25 \cdot \left(t\_0 \cdot \log \left(e^{t\_0}\right)\right)\right), \frac{4}{s}, 1\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. 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. associate-*r/N/A

      \[\leadsto \left(-s\right) \cdot \log \left(1 + \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}}\right) \]
    2. +-commutativeN/A

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

      \[\leadsto \left(-s\right) \cdot \log \left(\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} + 1\right) \]
    4. associate-/l*N/A

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

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

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

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

    Alternative 4: 25.2% accurate, 4.2× speedup?

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

        \[\leadsto \left(-s\right) \cdot \log \left(1 + \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}}\right) \]
      2. +-commutativeN/A

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

        \[\leadsto \left(-s\right) \cdot \log \left(\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} + 1\right) \]
      4. associate-/l*N/A

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

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

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

      \[\leadsto \left(-s\right) \cdot \log \left(1 + \color{blue}{\frac{\mathsf{PI}\left(\right)}{s}}\right) \]
    7. Step-by-step derivation
      1. Applied rewrites25.5%

        \[\leadsto \left(-s\right) \cdot \log \left(\frac{\mathsf{PI}\left(\right)}{s} + \color{blue}{1}\right) \]
      2. Add Preprocessing

      Alternative 5: 12.0% accurate, 7.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{-\mathsf{PI}\left(\right)}\\ \left(-s\right) \cdot \left(\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), -0.5, 0.25 \cdot \left(t\_0 \cdot t\_0\right)\right) \cdot \frac{4}{s}\right) \end{array} \end{array} \]
      (FPCore (u s)
       :precision binary32
       (let* ((t_0 (sqrt (- (PI)))))
         (* (- s) (* (fma (* u (PI)) -0.5 (* 0.25 (* t_0 t_0))) (/ 4.0 s)))))
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \sqrt{-\mathsf{PI}\left(\right)}\\
      \left(-s\right) \cdot \left(\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), -0.5, 0.25 \cdot \left(t\_0 \cdot t\_0\right)\right) \cdot \frac{4}{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. fp-cancel-sub-sign-invN/A

          \[\leadsto \left(-s\right) \cdot \left(\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 \frac{4}{s}\right) \]
        6. distribute-rgt-out--N/A

          \[\leadsto \left(-s\right) \cdot \left(\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 \frac{4}{s}\right) \]
        7. metadata-evalN/A

          \[\leadsto \left(-s\right) \cdot \left(\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 \frac{4}{s}\right) \]
        8. associate-*r*N/A

          \[\leadsto \left(-s\right) \cdot \left(\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 \frac{4}{s}\right) \]
        9. metadata-evalN/A

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

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

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

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

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

          \[\leadsto \left(-s\right) \cdot \left(\mathsf{fma}\left(u \cdot \mathsf{PI}\left(\right), \frac{-1}{2}, \frac{1}{4} \cdot \color{blue}{\mathsf{PI}\left(\right)}\right) \cdot \frac{4}{s}\right) \]
        15. lower-/.f3211.3

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

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

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

        Alternative 6: 12.3% accurate, 9.1× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{PI}\left(\right)}{u}\\ \mathsf{fma}\left(\frac{-1}{u}, t\_0, \mathsf{fma}\left(t\_0, 2, 0\right)\right) \cdot \left(u \cdot u\right) \end{array} \end{array} \]
        (FPCore (u s)
         :precision binary32
         (let* ((t_0 (/ (PI) u))) (* (fma (/ -1.0 u) t_0 (fma t_0 2.0 0.0)) (* u u))))
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \frac{\mathsf{PI}\left(\right)}{u}\\
        \mathsf{fma}\left(\frac{-1}{u}, t\_0, \mathsf{fma}\left(t\_0, 2, 0\right)\right) \cdot \left(u \cdot u\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 \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) + \frac{-1}{2} \cdot \frac{-16 \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)}^{2} + -2 \cdot \left(-8 \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)}^{2} + -4 \cdot \left(\frac{-1}{8} \cdot {\mathsf{PI}\left(\right)}^{2} + \frac{1}{8} \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right)}{s}} \]
        4. Applied rewrites7.7%

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

          \[\leadsto \frac{-1}{2} \cdot \color{blue}{\frac{-16 \cdot {\left(\frac{-1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)}^{2} + 16 \cdot {\left(\frac{-1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)}^{2}}{s}} \]
        6. Step-by-step derivation
          1. Applied rewrites10.3%

            \[\leadsto 0 \]
          2. Taylor expanded in u around inf

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

            \[\leadsto \mathsf{fma}\left(\frac{-1}{u}, \frac{\mathsf{PI}\left(\right)}{u}, \left(0 + \frac{0}{u \cdot u}\right) + \mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{u}, 2, \frac{0}{u}\right)\right) \cdot \color{blue}{\left(u \cdot u\right)} \]
          4. Final simplification10.3%

            \[\leadsto \mathsf{fma}\left(\frac{-1}{u}, \frac{\mathsf{PI}\left(\right)}{u}, \mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{u}, 2, 0\right)\right) \cdot \left(u \cdot u\right) \]
          5. Add Preprocessing

          Alternative 7: 11.5% accurate, 36.4× speedup?

          \[\begin{array}{l} \\ 2 \cdot \left(\mathsf{PI}\left(\right) \cdot u\right) - \mathsf{PI}\left(\right) \end{array} \]
          (FPCore (u s) :precision binary32 (- (* 2.0 (* (PI) u)) (PI)))
          \begin{array}{l}
          
          \\
          2 \cdot \left(\mathsf{PI}\left(\right) \cdot u\right) - \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 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.0%

            \[\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. 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. fp-cancel-sub-sign-invN/A

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

              \[\leadsto -4 \cdot \left(u \cdot \left(\frac{-1}{4} \cdot \mathsf{PI}\left(\right) - \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right) + \color{blue}{\frac{1}{4}} \cdot \mathsf{PI}\left(\right)\right) \]
            3. distribute-lft-inN/A

              \[\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)\right) + -4 \cdot \left(\frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)} \]
            4. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(2, \mathsf{PI}\left(\right) \cdot u, \color{blue}{-\mathsf{PI}\left(\right)}\right) \]
            18. lower-PI.f3211.3

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

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

            \[\leadsto 2 \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) - \color{blue}{\mathsf{PI}\left(\right)} \]
          10. Step-by-step derivation
            1. Applied rewrites11.5%

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

            Alternative 8: 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.3

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

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

            Alternative 9: 10.3% accurate, 510.0× speedup?

            \[\begin{array}{l} \\ 0 \end{array} \]
            (FPCore (u s) :precision binary32 0.0)
            float code(float u, float s) {
            	return 0.0f;
            }
            
            real(4) function code(u, s)
                real(4), intent (in) :: u
                real(4), intent (in) :: s
                code = 0.0e0
            end function
            
            function code(u, s)
            	return Float32(0.0)
            end
            
            function tmp = code(u, s)
            	tmp = single(0.0);
            end
            
            \begin{array}{l}
            
            \\
            0
            \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) + \frac{-1}{2} \cdot \frac{-16 \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)}^{2} + -2 \cdot \left(-8 \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)}^{2} + -4 \cdot \left(\frac{-1}{8} \cdot {\mathsf{PI}\left(\right)}^{2} + \frac{1}{8} \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right)}{s}} \]
            4. Applied rewrites7.9%

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

              \[\leadsto \frac{-1}{2} \cdot \color{blue}{\frac{-16 \cdot {\left(\frac{-1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)}^{2} + 16 \cdot {\left(\frac{-1}{2} \cdot \left(u \cdot \mathsf{PI}\left(\right)\right) + \frac{1}{4} \cdot \mathsf{PI}\left(\right)\right)}^{2}}{s}} \]
            6. Step-by-step derivation
              1. Applied rewrites10.3%

                \[\leadsto 0 \]
              2. Add Preprocessing

              Reproduce

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