Average Error: 0.7 → 0.4
Time: 26.7s
Precision: binary32
\[0 < cosTheta \land cosTheta < 0.9999 \land -1 < c \land c < 1\]
\[\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}} \]
\[\begin{array}{l} t_0 := \sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\\ t_1 := \left(1 + c \cdot c\right) - c\\ t_0 \cdot \frac{t_1}{t_0 \cdot \left(1 + {c}^{3}\right) + t_1 \cdot \sqrt{1 - \left(cosTheta + cosTheta\right)}} \end{array} \]
\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}}
\begin{array}{l}
t_0 := \sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\\
t_1 := \left(1 + c \cdot c\right) - c\\
t_0 \cdot \frac{t_1}{t_0 \cdot \left(1 + {c}^{3}\right) + t_1 \cdot \sqrt{1 - \left(cosTheta + cosTheta\right)}}
\end{array}
(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
 (let* ((t_0 (* (sqrt PI) (* cosTheta (pow (exp cosTheta) cosTheta))))
        (t_1 (- (+ 1.0 (* c c)) c)))
   (*
    t_0
    (/
     t_1
     (+
      (* t_0 (+ 1.0 (pow c 3.0)))
      (* t_1 (sqrt (- 1.0 (+ 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) {
	float t_0 = sqrtf((float) M_PI) * (cosTheta * powf(expf(cosTheta), cosTheta));
	float t_1 = (1.0f + (c * c)) - c;
	return t_0 * (t_1 / ((t_0 * (1.0f + powf(c, 3.0f))) + (t_1 * sqrtf(1.0f - (cosTheta + cosTheta)))));
}

Error

Bits error versus cosTheta

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)}}} \]
  3. Using strategy rm
  4. Applied flip3-+_binary320.5

    \[\leadsto \frac{1}{\color{blue}{\frac{{1}^{3} + {c}^{3}}{1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)}} + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)}} \]
  5. Applied frac-add_binary320.5

    \[\leadsto \frac{1}{\color{blue}{\frac{\left({1}^{3} + {c}^{3}\right) \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right) + \left(1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)\right) \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}}{\left(1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)\right) \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right)}}} \]
  6. Applied associate-/r/_binary320.4

    \[\leadsto \color{blue}{\frac{1}{\left({1}^{3} + {c}^{3}\right) \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right) + \left(1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)\right) \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}} \cdot \left(\left(1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)\right) \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right)\right)} \]
  7. Simplified0.5

    \[\leadsto \color{blue}{\frac{1}{\left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right) \cdot \left(1 + {c}^{3}\right) + \sqrt{1 - \left(cosTheta + cosTheta\right)} \cdot \left(1 + \left(c \cdot c - c\right)\right)}} \cdot \left(\left(1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)\right) \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right)\right) \]
  8. Using strategy rm
  9. Applied associate-*r*_binary320.4

    \[\leadsto \color{blue}{\left(\frac{1}{\left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right) \cdot \left(1 + {c}^{3}\right) + \sqrt{1 - \left(cosTheta + cosTheta\right)} \cdot \left(1 + \left(c \cdot c - c\right)\right)} \cdot \left(1 \cdot 1 + \left(c \cdot c - 1 \cdot c\right)\right)\right) \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right)} \]
  10. Simplified0.4

    \[\leadsto \color{blue}{\frac{\left(1 + c \cdot c\right) - c}{\left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right) \cdot \left(1 + {c}^{3}\right) + \left(\left(1 + c \cdot c\right) - c\right) \cdot \sqrt{1 - \left(cosTheta + cosTheta\right)}}} \cdot \left(\sqrt{\pi} \cdot \left(cosTheta \cdot {\left(e^{cosTheta}\right)}^{cosTheta}\right)\right) \]
  11. Final simplification0.4

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

Reproduce

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