Average Error: 0.3 → 0.3
Time: 10.6s
Precision: binary32
Cost: 23136
\[\left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right) \land \left(0 \leq s \land s \leq 1.0651631\right)\]
\[\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) \]
\[\left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{-\frac{\pi}{s}}} + \frac{1 - u}{1 + e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\pi}{s}\right)\right)}}} + -1\right) \]
(FPCore (u s)
 :precision binary32
 (*
  (- 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))))
(FPCore (u s)
 :precision binary32
 (*
  (- s)
  (log
   (+
    (/
     1.0
     (+
      (/ u (+ 1.0 (exp (- (/ PI s)))))
      (/ (- 1.0 u) (+ 1.0 (exp (expm1 (log1p (/ PI s))))))))
    -1.0))))
float code(float u, float s) {
	return -s * logf(((1.0f / ((u * ((1.0f / (1.0f + expf((-((float) M_PI) / s)))) - (1.0f / (1.0f + expf((((float) M_PI) / s)))))) + (1.0f / (1.0f + expf((((float) M_PI) / s)))))) - 1.0f));
}
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(expm1f(log1pf((((float) M_PI) / s)))))))) + -1.0f));
}
function code(u, 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)))) - Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) / s)))))) + Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(pi) / s)))))) - Float32(1.0))))
end
function code(u, s)
	return Float32(Float32(-s) * 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(expm1(log1p(Float32(Float32(pi) / s)))))))) + Float32(-1.0))))
end
\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)
\left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{-\frac{\pi}{s}}} + \frac{1 - u}{1 + e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\pi}{s}\right)\right)}}} + -1\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 0.3

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

    \[\leadsto \color{blue}{\left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}} + -1\right)} \]
    Proof
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (/.f32 u (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 (-.f32 1 u) (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (/.f32 (Rewrite<= *-rgt-identity_binary32 (*.f32 u 1)) (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 (-.f32 1 u) (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (Rewrite<= associate-*r/_binary32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))))) (/.f32 (-.f32 1 u) (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (Rewrite=> div-sub_binary32 (-.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))) (/.f32 u (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (-.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))) (/.f32 (Rewrite<= *-lft-identity_binary32 (*.f32 1 u)) (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (-.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))) (Rewrite<= associate-*l/_binary32 (*.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))) u))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (Rewrite=> cancel-sign-sub-inv_binary32 (+.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))) (*.f32 (neg.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))) u))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (Rewrite<= +-commutative_binary32 (+.f32 (*.f32 (neg.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))) u) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (+.f32 (Rewrite=> *-commutative_binary32 (*.f32 u (neg.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (Rewrite<= associate-+l+_binary32 (+.f32 (+.f32 (*.f32 u (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s))))) (*.f32 u (neg.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (Rewrite<= distribute-lft-in_binary32 (*.f32 u (+.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (neg.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (Rewrite<= sub-neg_binary32 (-.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s))))))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) -1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (+.f32 (/.f32 1 (+.f32 (*.f32 u (-.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) (Rewrite<= metadata-eval (neg.f32 1))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (neg.f32 s) (log.f32 (Rewrite<= sub-neg_binary32 (-.f32 (/.f32 1 (+.f32 (*.f32 u (-.f32 (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (neg.f32 (PI.f32)) s)))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) (/.f32 1 (+.f32 1 (exp.f32 (/.f32 (PI.f32) s)))))) 1)))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.3

    \[\leadsto \left(-s\right) \cdot \log \left(\frac{1}{\frac{u}{1 + e^{\frac{-\pi}{s}}} + \frac{1 - u}{1 + e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\pi}{s}\right)\right)}}}} + -1\right) \]
  4. Final simplification0.3

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

Alternatives

Alternative 1
Error0.3
Cost16736
\[s \cdot \left(-\log \left(-1 + \frac{1}{\frac{u}{1 + e^{-\frac{\pi}{s}}} + \frac{1 - u}{1 + e^{\frac{\pi}{s}}}}\right)\right) \]
Alternative 2
Error23.9
Cost13024
\[s \cdot \left(\left(\log s - \log \pi\right) - \frac{s}{\pi}\right) \]
Alternative 3
Error23.9
Cost9984
\[s \cdot \left(\left(\log s - \log \pi\right) + \left(1 + u\right) \cdot \left(u \cdot 2\right)\right) \]
Alternative 4
Error23.9
Cost9856
\[s \cdot \left(\log s - \left(\log \pi + u \cdot -2\right)\right) \]
Alternative 5
Error23.9
Cost9728
\[s \cdot \left(\log s - \log \pi\right) \]
Alternative 6
Error24.0
Cost6560
\[\left(-s\right) \cdot \mathsf{log1p}\left(\frac{\pi}{s}\right) \]
Alternative 7
Error28.3
Cost3712
\[4 \cdot \frac{\pi \cdot \left(0.0625 + \left(u \cdot u\right) \cdot -0.25\right)}{-0.25 + u \cdot -0.5} \]
Alternative 8
Error28.3
Cost3456
\[4 \cdot \left(\pi \cdot \left(-0.25 + u \cdot 0.5\right)\right) \]
Alternative 9
Error28.4
Cost3232
\[-\pi \]
Alternative 10
Error28.7
Cost96
\[s \cdot 0 \]

Error

Reproduce

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