Beckmann Sample, normalization factor

Percentage Accurate: 97.9% → 98.8%
Time: 39.0s
Alternatives: 8
Speedup: 1.2×

Specification

?
\[\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}} \]
(FPCore (cosTheta c)
  :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))))))
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))));
}
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 tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(1.0) + c) + (((single(1.0) / sqrt(single(pi))) * (sqrt(((single(1.0) - cosTheta) - cosTheta)) / 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}}

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 8 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: 97.9% accurate, 1.0× speedup?

\[\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}} \]
(FPCore (cosTheta c)
  :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))))))
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))));
}
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 tmp = code(cosTheta, c)
	tmp = single(1.0) / ((single(1.0) + c) + (((single(1.0) / sqrt(single(pi))) * (sqrt(((single(1.0) - cosTheta) - cosTheta)) / 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}}

Alternative 1: 98.8% accurate, 0.8× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\begin{array}{l} t_0 := e^{cosTheta \cdot cosTheta}\\ cosTheta \cdot \frac{t\_0}{\mathsf{fma}\left(t\_0 \cdot cosTheta, c - -1, \sqrt{\frac{\mathsf{fma}\left(-2, cosTheta, 1\right)}{\pi}}\right)} \end{array} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (let* ((t_0 (exp (* cosTheta cosTheta))))
  (*
   cosTheta
   (/
    t_0
    (fma
     (* t_0 cosTheta)
     (- c -1.0)
     (sqrt (/ (fma -2.0 cosTheta 1.0) PI)))))))
float code(float cosTheta, float c) {
	float t_0 = expf((cosTheta * cosTheta));
	return cosTheta * (t_0 / fmaf((t_0 * cosTheta), (c - -1.0f), sqrtf((fmaf(-2.0f, cosTheta, 1.0f) / ((float) M_PI)))));
}
function code(cosTheta, c)
	t_0 = exp(Float32(cosTheta * cosTheta))
	return Float32(cosTheta * Float32(t_0 / fma(Float32(t_0 * cosTheta), Float32(c - Float32(-1.0)), sqrt(Float32(fma(Float32(-2.0), cosTheta, Float32(1.0)) / Float32(pi))))))
end
\begin{array}{l}
t_0 := e^{cosTheta \cdot cosTheta}\\
cosTheta \cdot \frac{t\_0}{\mathsf{fma}\left(t\_0 \cdot cosTheta, c - -1, \sqrt{\frac{\mathsf{fma}\left(-2, cosTheta, 1\right)}{\pi}}\right)}
\end{array}
Derivation
  1. Initial program 97.9%

    \[\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. Applied rewrites98.0%

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

    \[\leadsto \frac{e^{cosTheta \cdot cosTheta} \cdot cosTheta}{\mathsf{fma}\left(e^{cosTheta \cdot cosTheta} \cdot cosTheta, c - -1, \sqrt{\frac{\mathsf{fma}\left(-2, cosTheta, 1\right)}{\pi}}\right)} \]
  4. Applied rewrites98.8%

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

Alternative 2: 98.5% accurate, 1.2× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\left(1 + c\right) + \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot \left(1.7724539041519165 \cdot cosTheta\right)}} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.0
 (+
  (+ 1.0 c)
  (/
   (sqrt (fma -2.0 cosTheta 1.0))
   (* (exp (* cosTheta cosTheta)) (* 1.7724539041519165 cosTheta))))))
float code(float cosTheta, float c) {
	return 1.0f / ((1.0f + c) + (sqrtf(fmaf(-2.0f, cosTheta, 1.0f)) / (expf((cosTheta * cosTheta)) * (1.7724539041519165f * cosTheta))));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(sqrt(fma(Float32(-2.0), cosTheta, Float32(1.0))) / Float32(exp(Float32(cosTheta * cosTheta)) * Float32(Float32(1.7724539041519165) * cosTheta)))))
end
\frac{1}{\left(1 + c\right) + \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot \left(1.7724539041519165 \cdot cosTheta\right)}}
Derivation
  1. Initial program 97.9%

    \[\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. Applied rewrites98.5%

    \[\leadsto \frac{1}{\left(1 + c\right) + \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot \left(\sqrt{\pi} \cdot cosTheta\right)}} \]
  3. Evaluated real constant98.5%

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

Alternative 3: 98.0% accurate, 1.2× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\mathsf{fma}\left(0.564189612865448, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, c - -1\right)} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.0
 (fma
  0.564189612865448
  (/
   (sqrt (fma -2.0 cosTheta 1.0))
   (* (exp (* cosTheta cosTheta)) cosTheta))
  (- c -1.0))))
float code(float cosTheta, float c) {
	return 1.0f / fmaf(0.564189612865448f, (sqrtf(fmaf(-2.0f, cosTheta, 1.0f)) / (expf((cosTheta * cosTheta)) * cosTheta)), (c - -1.0f));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / fma(Float32(0.564189612865448), Float32(sqrt(fma(Float32(-2.0), cosTheta, Float32(1.0))) / Float32(exp(Float32(cosTheta * cosTheta)) * cosTheta)), Float32(c - Float32(-1.0))))
end
\frac{1}{\mathsf{fma}\left(0.564189612865448, \frac{\sqrt{\mathsf{fma}\left(-2, cosTheta, 1\right)}}{e^{cosTheta \cdot cosTheta} \cdot cosTheta}, c - -1\right)}
Derivation
  1. Initial program 97.9%

    \[\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. Evaluated real constant97.9%

    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  3. Applied rewrites98.0%

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

Alternative 4: 97.1% accurate, 2.0× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\left(\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, 0.282094806432724, -0.846284419298172\right), cosTheta, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.0
 (+
  (-
   (fma
    (fma cosTheta 0.282094806432724 -0.846284419298172)
    cosTheta
    c)
   -0.435810387134552)
  (/ 0.564189612865448 cosTheta))))
float code(float cosTheta, float c) {
	return 1.0f / ((fmaf(fmaf(cosTheta, 0.282094806432724f, -0.846284419298172f), cosTheta, c) - -0.435810387134552f) + (0.564189612865448f / cosTheta));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(fma(fma(cosTheta, Float32(0.282094806432724), Float32(-0.846284419298172)), cosTheta, c) - Float32(-0.435810387134552)) + Float32(Float32(0.564189612865448) / cosTheta)))
end
\frac{1}{\left(\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, 0.282094806432724, -0.846284419298172\right), cosTheta, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}}
Derivation
  1. Initial program 97.9%

    \[\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. Evaluated real constant97.9%

    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  3. Taylor expanded in cosTheta around 0

    \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + cosTheta \cdot \left(\frac{9465531}{33554432} \cdot cosTheta - \frac{28396593}{33554432}\right)\right)\right)}{cosTheta}} \]
  4. Applied rewrites97.1%

    \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + cosTheta \cdot \left(0.282094806432724 \cdot cosTheta - 0.846284419298172\right)\right)\right)}{cosTheta}} \]
  5. Applied rewrites97.1%

    \[\leadsto \frac{1}{\left(\mathsf{fma}\left(\mathsf{fma}\left(cosTheta, 0.282094806432724, -0.846284419298172\right), cosTheta, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
  6. Add Preprocessing

Alternative 5: 96.5% accurate, 2.5× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[\frac{1}{\left(\mathsf{fma}\left(cosTheta, -0.846284419298172, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (/
 1.0
 (+
  (- (fma cosTheta -0.846284419298172 c) -0.435810387134552)
  (/ 0.564189612865448 cosTheta))))
float code(float cosTheta, float c) {
	return 1.0f / ((fmaf(cosTheta, -0.846284419298172f, c) - -0.435810387134552f) + (0.564189612865448f / cosTheta));
}
function code(cosTheta, c)
	return Float32(Float32(1.0) / Float32(Float32(fma(cosTheta, Float32(-0.846284419298172), c) - Float32(-0.435810387134552)) + Float32(Float32(0.564189612865448) / cosTheta)))
end
\frac{1}{\left(\mathsf{fma}\left(cosTheta, -0.846284419298172, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}}
Derivation
  1. Initial program 97.9%

    \[\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. Evaluated real constant97.9%

    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  3. Taylor expanded in cosTheta around 0

    \[\leadsto \frac{1}{\frac{\frac{9465531}{16777216} + cosTheta \cdot \left(\frac{7311685}{16777216} + \left(c + \frac{-28396593}{33554432} \cdot cosTheta\right)\right)}{cosTheta}} \]
  4. Applied rewrites96.5%

    \[\leadsto \frac{1}{\frac{0.564189612865448 + cosTheta \cdot \left(0.435810387134552 + \left(c + -0.846284419298172 \cdot cosTheta\right)\right)}{cosTheta}} \]
  5. Applied rewrites96.5%

    \[\leadsto \frac{1}{\left(\mathsf{fma}\left(cosTheta, -0.846284419298172, c\right) - -0.435810387134552\right) + \frac{0.564189612865448}{cosTheta}} \]
  6. Add Preprocessing

Alternative 6: 95.6% accurate, 3.1× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (*
 cosTheta
 (+
  1.7724537588012759
  (* -3.141592327088772 (* cosTheta (+ 0.435810387134552 c))))))
float code(float cosTheta, float c) {
	return cosTheta * (1.7724537588012759f + (-3.141592327088772f * (cosTheta * (0.435810387134552f + c))));
}
real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = costheta * (1.7724537588012759e0 + ((-3.141592327088772e0) * (costheta * (0.435810387134552e0 + c))))
end function
function code(cosTheta, c)
	return Float32(cosTheta * Float32(Float32(1.7724537588012759) + Float32(Float32(-3.141592327088772) * Float32(cosTheta * Float32(Float32(0.435810387134552) + c)))))
end
function tmp = code(cosTheta, c)
	tmp = cosTheta * (single(1.7724537588012759) + (single(-3.141592327088772) * (cosTheta * (single(0.435810387134552) + c))));
end
cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right)
Derivation
  1. Initial program 97.9%

    \[\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. Evaluated real constant97.9%

    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  3. Taylor expanded in cosTheta around 0

    \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right) \]
  4. Applied rewrites95.6%

    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
  5. Add Preprocessing

Alternative 7: 95.4% accurate, 5.0× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right) \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (* cosTheta (+ 1.7724537588012759 (* -1.3691385682874957 cosTheta))))
float code(float cosTheta, float c) {
	return cosTheta * (1.7724537588012759f + (-1.3691385682874957f * cosTheta));
}
real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = costheta * (1.7724537588012759e0 + ((-1.3691385682874957e0) * costheta))
end function
function code(cosTheta, c)
	return Float32(cosTheta * Float32(Float32(1.7724537588012759) + Float32(Float32(-1.3691385682874957) * cosTheta)))
end
function tmp = code(cosTheta, c)
	tmp = cosTheta * (single(1.7724537588012759) + (single(-1.3691385682874957) * cosTheta));
end
cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right)
Derivation
  1. Initial program 97.9%

    \[\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. Evaluated real constant97.9%

    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  3. Taylor expanded in cosTheta around 0

    \[\leadsto cosTheta \cdot \left(\frac{16777216}{9465531} + \frac{-281474976710656}{89596277111961} \cdot \left(cosTheta \cdot \left(\frac{7311685}{16777216} + c\right)\right)\right) \]
  4. Applied rewrites95.6%

    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -3.141592327088772 \cdot \left(cosTheta \cdot \left(0.435810387134552 + c\right)\right)\right) \]
  5. Taylor expanded in c around 0

    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + \frac{-122669718568960}{89596277111961} \cdot cosTheta\right) \]
  6. Applied rewrites95.4%

    \[\leadsto cosTheta \cdot \left(1.7724537588012759 + -1.3691385682874957 \cdot cosTheta\right) \]
  7. Add Preprocessing

Alternative 8: 92.9% accurate, 11.9× speedup?

\[\left(0 < cosTheta \land cosTheta < 0.9999\right) \land \left(-1 < c \land c < 1\right)\]
\[1.7724537588012759 \cdot cosTheta \]
(FPCore (cosTheta c)
  :precision binary32
  :pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999))
     (and (< -1.0 c) (< c 1.0)))
  (* 1.7724537588012759 cosTheta))
float code(float cosTheta, float c) {
	return 1.7724537588012759f * cosTheta;
}
real(4) function code(costheta, c)
use fmin_fmax_functions
    real(4), intent (in) :: costheta
    real(4), intent (in) :: c
    code = 1.7724537588012759e0 * costheta
end function
function code(cosTheta, c)
	return Float32(Float32(1.7724537588012759) * cosTheta)
end
function tmp = code(cosTheta, c)
	tmp = single(1.7724537588012759) * cosTheta;
end
1.7724537588012759 \cdot cosTheta
Derivation
  1. Initial program 97.9%

    \[\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. Evaluated real constant97.9%

    \[\leadsto \frac{1}{\left(1 + c\right) + \left(0.564189612865448 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
  3. Taylor expanded in cosTheta around 0

    \[\leadsto \frac{16777216}{9465531} \cdot cosTheta \]
  4. Applied rewrites92.9%

    \[\leadsto 1.7724537588012759 \cdot cosTheta \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2026089 +o generate:egglog
(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))))))