Average Error: 0.7 → 0.5
Time: 15.0s
Precision: binary32
Cost: 19680
\[\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}{1 + \left(c + \frac{\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)}\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
  (+
   1.0
   (+
    c
    (/
     (sqrt (fma cosTheta -2.0 1.0))
     (* (sqrt PI) (* cosTheta (pow (exp cosTheta) cosTheta))))))))
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 / (1.0f + (c + (sqrtf(fmaf(cosTheta, -2.0f, 1.0f)) / (sqrtf(((float) M_PI)) * (cosTheta * powf(expf(cosTheta), cosTheta))))));
}
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) / Float32(Float32(1.0) + Float32(c + Float32(sqrt(fma(cosTheta, Float32(-2.0), Float32(1.0))) / Float32(sqrt(Float32(pi)) * Float32(cosTheta * (exp(cosTheta) ^ cosTheta)))))))
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}{1 + \left(c + \frac{\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)}\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}{1 + \left(c + \frac{\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}}{\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)}\right)}} \]
    Proof
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (fma.f32 cosTheta -2 1)) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (fma.f32 cosTheta (Rewrite<= metadata-eval (neg.f32 2)) 1)) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (Rewrite<= fma-def_binary32 (+.f32 (*.f32 cosTheta (neg.f32 2)) 1))) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (+.f32 (Rewrite<= distribute-rgt-neg-in_binary32 (neg.f32 (*.f32 cosTheta 2))) 1)) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (+.f32 (neg.f32 (Rewrite<= *-commutative_binary32 (*.f32 2 cosTheta))) 1)) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (+.f32 (neg.f32 (Rewrite<= count-2_binary32 (+.f32 cosTheta cosTheta))) 1)) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (+.f32 (Rewrite<= distribute-neg-out_binary32 (+.f32 (neg.f32 cosTheta) (neg.f32 cosTheta))) 1)) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 1 (+.f32 (neg.f32 cosTheta) (neg.f32 cosTheta))))) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (+.f32 1 (Rewrite=> distribute-neg-out_binary32 (neg.f32 (+.f32 cosTheta cosTheta))))) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (Rewrite<= sub-neg_binary32 (-.f32 1 (+.f32 cosTheta cosTheta)))) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (Rewrite<= associate--l-_binary32 (-.f32 (-.f32 1 cosTheta) cosTheta))) (*.f32 (sqrt.f32 (PI.f32)) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 5 points increase in error, 2 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (Rewrite<= remove-double-div_binary32 (/.f32 1 (/.f32 1 (sqrt.f32 (PI.f32))))) (*.f32 cosTheta (pow.f32 (exp.f32 cosTheta) cosTheta))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (/.f32 1 (/.f32 1 (sqrt.f32 (PI.f32)))) (*.f32 cosTheta (Rewrite<= exp-prod_binary32 (exp.f32 (*.f32 cosTheta cosTheta))))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (/.f32 1 (/.f32 1 (sqrt.f32 (PI.f32)))) (Rewrite<= /-rgt-identity_binary32 (/.f32 (*.f32 cosTheta (exp.f32 (*.f32 cosTheta cosTheta))) 1))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (/.f32 1 (/.f32 1 (sqrt.f32 (PI.f32)))) (Rewrite=> associate-/l*_binary32 (/.f32 cosTheta (/.f32 1 (exp.f32 (*.f32 cosTheta cosTheta)))))))))): 0 points increase in error, 1 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (/.f32 1 (/.f32 1 (sqrt.f32 (PI.f32)))) (/.f32 cosTheta (Rewrite<= exp-neg_binary32 (exp.f32 (neg.f32 (*.f32 cosTheta cosTheta)))))))))): 2 points increase in error, 4 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (*.f32 (/.f32 1 (/.f32 1 (sqrt.f32 (PI.f32)))) (/.f32 cosTheta (exp.f32 (Rewrite<= distribute-lft-neg-out_binary32 (*.f32 (neg.f32 cosTheta) cosTheta))))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (Rewrite<= times-frac_binary32 (/.f32 (*.f32 1 cosTheta) (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta))))))))): 43 points increase in error, 4 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 (Rewrite=> *-lft-identity_binary32 cosTheta) (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) (/.f32 cosTheta (Rewrite<= *-commutative_binary32 (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (/.f32 1 (sqrt.f32 (PI.f32)))))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (Rewrite=> associate-/r/_binary32 (*.f32 (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) cosTheta) (*.f32 (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)) (/.f32 1 (sqrt.f32 (PI.f32))))))))): 38 points increase in error, 44 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (*.f32 (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) cosTheta) (Rewrite=> *-commutative_binary32 (*.f32 (/.f32 1 (sqrt.f32 (PI.f32))) (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta)))))))): 0 points increase in error, 0 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (Rewrite<= associate-*l*_binary32 (*.f32 (*.f32 (/.f32 (sqrt.f32 (-.f32 (-.f32 1 cosTheta) cosTheta)) cosTheta) (/.f32 1 (sqrt.f32 (PI.f32)))) (exp.f32 (*.f32 (neg.f32 cosTheta) cosTheta))))))): 2 points increase in error, 1 points decrease in error
    (/.f32 1 (+.f32 1 (+.f32 c (*.f32 (Rewrite<= *-commutative_binary32 (*.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, 0 points decrease in error
    (/.f32 1 (Rewrite<= associate-+l+_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, 0 points decrease in error
  3. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost16576
\[\frac{1}{1 + \left(c + \sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)} \cdot \frac{1}{cosTheta \cdot \left(\sqrt{\pi} \cdot e^{cosTheta \cdot cosTheta}\right)}\right)} \]
Alternative 2
Error0.7
Cost13472
\[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{cosTheta \cdot \left(-cosTheta\right)}} \]
Alternative 3
Error0.6
Cost13312
\[\frac{1}{1 + \left(c + \frac{\sqrt{\frac{\mathsf{fma}\left(cosTheta, -2, 1\right)}{\pi}}}{cosTheta \cdot e^{cosTheta \cdot cosTheta}}\right)} \]
Alternative 4
Error1.0
Cost10464
\[\frac{1}{\left(1 + c\right) + e^{cosTheta \cdot \left(-cosTheta\right)} \cdot \left(\sqrt{\frac{1}{\pi}} \cdot \left(\left(\frac{1}{cosTheta} + -1\right) + cosTheta \cdot \left(-0.5 + cosTheta \cdot -0.5\right)\right)\right)} \]
Alternative 5
Error1.1
Cost6976
\[\frac{1}{1 + \left(c + \sqrt{\frac{1}{\pi}} \cdot \left(\left(\frac{1}{cosTheta} + -1\right) + cosTheta \cdot -1.5\right)\right)} \]
Alternative 6
Error1.2
Cost6912
\[\frac{1}{1 + \sqrt{\frac{1}{\pi}} \cdot \left(\left(\frac{1}{cosTheta} + -1\right) + cosTheta \cdot -1.5\right)} \]
Alternative 7
Error1.4
Cost6784
\[\frac{1}{\left(1 + c\right) + \frac{\frac{1}{cosTheta} + -1}{\sqrt{\pi}}} \]
Alternative 8
Error2.2
Cost6464
\[cosTheta \cdot \sqrt{\pi} \]
Alternative 9
Error28.6
Cost96
\[1 - c \]
Alternative 10
Error28.6
Cost32
\[1 \]

Error

Reproduce

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