Average Error: 0.7 → 0.5
Time: 16.3s
Precision: binary32
Cost: 22848
\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
\[\frac{1}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}, \frac{{\left(e^{cosTheta}\right)}^{\left(-cosTheta\right)}}{cosTheta \cdot \sqrt{\pi}}, 1 + c\right)} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (+ 1.0 c)
   (*
    (* (/ 1.0 (sqrt PI)) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
    (exp (* (- cosTheta) cosTheta))))))
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (fma
   (sqrt (fma cosTheta -2.0 1.0))
   (/ (pow (exp cosTheta) (- cosTheta)) (* cosTheta (sqrt PI)))
   (+ 1.0 c))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (((1.0f / sqrtf(((float) M_PI))) * (sqrtf(((1.0f - cosTheta) - cosTheta)) / cosTheta)) * expf((-cosTheta * cosTheta))));
}
float code(float cosTheta, float c) {
	return 1.0f / fmaf(sqrtf(fmaf(cosTheta, -2.0f, 1.0f)), (powf(expf(cosTheta), -cosTheta) / (cosTheta * sqrtf(((float) M_PI)))), (1.0f + c));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(Float32(Float32(Float32(1.0) / sqrt(Float32(pi))) * Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp(Float32(Float32(-cosTheta) * cosTheta)))))
end
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(sqrt(fma(cosTheta, Float32(-2.0), Float32(1.0))), Float32((exp(cosTheta) ^ Float32(-cosTheta)) / Float32(cosTheta * sqrt(Float32(pi)))), Float32(Float32(1.0) + c)))
end
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\frac{1}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}, \frac{{\left(e^{cosTheta}\right)}^{\left(-cosTheta\right)}}{cosTheta \cdot \sqrt{\pi}}, 1 + c\right)}

Error

Derivation

  1. Initial program 0.7

    \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  2. Simplified0.5

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}, \frac{{\left(e^{cosTheta}\right)}^{\left(-cosTheta\right)}}{\sqrt{\pi} \cdot cosTheta}, 1 + c\right)}} \]
    Proof
    (/.f32 1 (fma.f32 (sqrt.f32 (fma.f32 cosTheta -2 1)) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (fma.f32 cosTheta (Rewrite<= metadata-eval (+.f32 -1 -1)) 1)) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 12 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (Rewrite<= fma-def_binary32 (+.f32 (*.f32 cosTheta (+.f32 -1 -1)) 1))) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 12 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (+.f32 (Rewrite<= distribute-rgt-out_binary32 (+.f32 (*.f32 -1 cosTheta) (*.f32 -1 cosTheta))) 1)) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 25 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (+.f32 (+.f32 (*.f32 -1 cosTheta) (Rewrite<= neg-mul-1_binary32 (neg.f32 cosTheta))) 1)) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (+.f32 (+.f32 (Rewrite<= neg-mul-1_binary32 (neg.f32 cosTheta)) (neg.f32 cosTheta)) 1)) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 13 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 1 (+.f32 (neg.f32 cosTheta) (neg.f32 cosTheta))))) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 9 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (Rewrite<= associate-+l+_binary32 (+.f32 (+.f32 1 (neg.f32 cosTheta)) (neg.f32 cosTheta)))) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 3 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (+.f32 (Rewrite<= sub-neg_binary32 (-.f32 1 cosTheta)) (neg.f32 cosTheta))) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 25 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (Rewrite<= sub-neg_binary32 (-.f32 (-.f32 1 cosTheta) cosTheta))) (/.f32 (pow.f32 (exp.f32 cosTheta) (neg.f32 cosTheta)) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 13 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (Rewrite<= exp-prod_binary32 (exp.f32 (*.f32 cosTheta (neg.f32 cosTheta)))) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 13 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (exp.f32 (Rewrite<= *-commutative_binary32 (*.f32 (neg.f32 cosTheta) cosTheta))) (*.f32 (sqrt.f32 (PI.f32)) cosTheta)) (+.f32 1 c))): 0 points increase in error, 25 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (Rewrite<= *-commutative_binary32 (*.f32 cosTheta (sqrt.f32 (PI.f32))))) (+.f32 1 c))): 25 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (Rewrite<= associate-/l/_binary32 (/.f32 (/.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (sqrt.f32 (PI.f32))) cosTheta)) (+.f32 1 c))): 0 points increase in error, 25 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (/.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (Rewrite<= /-rgt-identity_binary32 (/.f32 (sqrt.f32 (PI.f32)) 1))) cosTheta) (+.f32 1 c))): 25 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (Rewrite<= associate-/l*_binary32 (/.f32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) 1) (sqrt.f32 (PI.f32)))) cosTheta) (+.f32 1 c))): 0 points increase in error, 25 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (Rewrite<= associate-*r/_binary32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (/.f32 1 (sqrt.f32 (PI.f32))))) cosTheta) (+.f32 1 c))): 9 points increase in error, 0 points decrease in error
    (/.f32 1 (fma.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (Rewrite<= associate-*r/_binary32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (/.f32 (/.f32 1 (sqrt.f32 (PI.f32))) cosTheta))) (+.f32 1 c))): 3 points increase in error, 9 points decrease in error
    (/.f32 1 (Rewrite<= fma-def_binary32 (+.f32 (*.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (/.f32 (/.f32 1 (sqrt.f32 (PI.f32))) cosTheta))) (+.f32 1 c)))): 22 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 (Rewrite<= *-commutative_binary32 (*.f32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (/.f32 (/.f32 1 (sqrt.f32 (PI.f32))) cosTheta)) (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)))) (+.f32 1 c))): 0 points increase in error, 25 points decrease in error
    (/.f32 1 (+.f32 (Rewrite<= associate-*r*_binary32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (*.f32 (/.f32 (/.f32 1 (sqrt.f32 (PI.f32))) cosTheta) (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta))))) (+.f32 1 c))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (Rewrite=> associate-*l/_binary32 (/.f32 (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta))) cosTheta))) (+.f32 1 c))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (Rewrite<= associate-*r/_binary32 (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) cosTheta)))) (+.f32 1 c))): 9 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 (Rewrite<= *-commutative_binary32 (*.f32 (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) cosTheta)) (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)))) (+.f32 1 c))): 12 points increase in error, 6 points decrease in error
    (/.f32 1 (Rewrite<= +-commutative_binary32 (+.f32 (+.f32 1 c) (*.f32 (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) cosTheta)) (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)))))): 0 points increase in error, 12 points decrease in error
  3. Final simplification0.5

    \[\leadsto \frac{1}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}, \frac{{\left(e^{cosTheta}\right)}^{\left(-cosTheta\right)}}{cosTheta \cdot \sqrt{\pi}}, 1 + c\right)} \]

Alternatives

Alternative 1
Error0.5
Cost16640
\[\frac{1}{c + \left(1 + \frac{\frac{\sqrt{1 + cosTheta \cdot -2}}{\sqrt{cosTheta \cdot \pi} \cdot \sqrt{cosTheta}}}{e^{cosTheta \cdot cosTheta}}\right)} \]
Alternative 2
Error0.5
Cost13376
\[\frac{1}{c + \left(1 + \frac{\frac{\sqrt{1 + cosTheta \cdot -2}}{cosTheta \cdot \sqrt{\pi}}}{e^{cosTheta \cdot cosTheta}}\right)} \]
Alternative 3
Error0.6
Cost10208
\[\frac{1}{c + \left(1 + \frac{\frac{\sqrt{\frac{-1 + cosTheta \cdot 2}{-\pi}}}{cosTheta}}{e^{cosTheta \cdot cosTheta}}\right)} \]
Alternative 4
Error0.8
Cost10144
\[\frac{1}{1 + \frac{\sqrt{\frac{-1 + cosTheta \cdot 2}{-\pi}}}{cosTheta \cdot e^{cosTheta \cdot cosTheta}}} \]
Alternative 5
Error1.3
Cost10112
\[\frac{1}{c + \left(1 + \frac{\frac{-1 + \frac{1}{cosTheta}}{\sqrt{\pi}}}{e^{cosTheta \cdot cosTheta}}\right)} \]
Alternative 6
Error1.5
Cost6848
\[\frac{1}{c + \left(1 + \frac{1}{\sqrt{\pi} \cdot \left(cosTheta + cosTheta \cdot cosTheta\right)}\right)} \]
Alternative 7
Error1.7
Cost6784
\[\frac{1}{1 + \left(-1 + \frac{1}{cosTheta}\right) \cdot \sqrt{\frac{1}{\pi}}} \]
Alternative 8
Error2.3
Cost6464
\[cosTheta \cdot \sqrt{\pi} \]
Alternative 9
Error28.5
Cost96
\[1 - c \]
Alternative 10
Error28.5
Cost32
\[1 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (cosTheta c)
  :name "Beckmann Sample, normalization factor"
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999)) (and (< -1.0 c) (< c 1.0)))
  (/ 1.0 (+ (+ 1.0 c) (* (* (/ 1.0 (sqrt PI)) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta)) (exp (* (- cosTheta) cosTheta))))))