Beckmann Sample, normalization factor

Percentage Accurate: 98.4% → 98.4%
Time: 1.8s
Alternatives: 1
Speedup: 1.0×

Specification

?
\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\begin{array}{l} \\ \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \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))))))
\begin{array}{l}

\\
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\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 1 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: 98.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \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))))))
\begin{array}{l}

\\
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}

Alternative 1: 98.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right) + \left(c + 1\right)} \end{array} \]
(FPCore (cosTheta c)
 :precision binary32
 (/
  1.0
  (+
   (*
    (exp (* (- cosTheta) cosTheta))
    (* (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta) (/ 1.0 (sqrt (PI)))))
   (+ c 1.0))))
\begin{array}{l}

\\
\frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right) + \left(c + 1\right)}
\end{array}
Derivation
  1. Initial program 98.0%

    \[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  2. Add Preprocessing
  3. Final simplification98.0%

    \[\leadsto \frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \left(\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right) + \left(c + 1\right)} \]
  4. Add Preprocessing

Reproduce

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