?

Average Error: 0.4 → 0.1
Time: 1.5min
Precision: binary64
Cost: 66308

?

\[\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}} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(c, c, 1 - c\right)\\ t_1 := t_0 \cdot cosTheta\\ t_2 := \sqrt{1 - cosTheta \cdot 2}\\ \mathbf{if}\;t_1 \ne 0:\\ \;\;\;\;\frac{t_1}{\mathsf{fma}\left(\frac{\frac{t_2}{e^{{cosTheta}^{2}}}}{\sqrt{\pi}}, t_0, {c}^{3} \cdot cosTheta + cosTheta\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(\mathsf{fma}\left(\frac{t_2}{\sqrt{\pi} \cdot cosTheta}, e^{-{cosTheta}^{2}}, c - -1\right)\right)}^{-1}\\ \end{array} \]
(FPCore (cosTheta c)
 :precision binary64
 (/
  1.0
  (+
   (+ 1.0 c)
   (*
    (* (/ 1.0 (sqrt PI)) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
    (exp (* (- cosTheta) cosTheta))))))
(FPCore (cosTheta c)
 :precision binary64
 (let* ((t_0 (fma c c (- 1.0 c)))
        (t_1 (* t_0 cosTheta))
        (t_2 (sqrt (- 1.0 (* cosTheta 2.0)))))
   (if (!= t_1 0.0)
     (/
      t_1
      (fma
       (/ (/ t_2 (exp (pow cosTheta 2.0))) (sqrt PI))
       t_0
       (+ (* (pow c 3.0) cosTheta) cosTheta)))
     (pow
      (fma
       (/ t_2 (* (sqrt PI) cosTheta))
       (exp (- (pow cosTheta 2.0)))
       (- c -1.0))
      -1.0))))
double code(double cosTheta, double c) {
	return 1.0 / ((1.0 + c) + (((1.0 / sqrt(((double) M_PI))) * (sqrt(((1.0 - cosTheta) - cosTheta)) / cosTheta)) * exp((-cosTheta * cosTheta))));
}
double code(double cosTheta, double c) {
	double t_0 = fma(c, c, (1.0 - c));
	double t_1 = t_0 * cosTheta;
	double t_2 = sqrt((1.0 - (cosTheta * 2.0)));
	double tmp;
	if (t_1 != 0.0) {
		tmp = t_1 / fma(((t_2 / exp(pow(cosTheta, 2.0))) / sqrt(((double) M_PI))), t_0, ((pow(c, 3.0) * cosTheta) + cosTheta));
	} else {
		tmp = pow(fma((t_2 / (sqrt(((double) M_PI)) * cosTheta)), exp(-pow(cosTheta, 2.0)), (c - -1.0)), -1.0);
	}
	return tmp;
}
function code(cosTheta, c)
	return Float64(1.0 / Float64(Float64(1.0 + c) + Float64(Float64(Float64(1.0 / sqrt(pi)) * Float64(sqrt(Float64(Float64(1.0 - cosTheta) - cosTheta)) / cosTheta)) * exp(Float64(Float64(-cosTheta) * cosTheta)))))
end
function code(cosTheta, c)
	t_0 = fma(c, c, Float64(1.0 - c))
	t_1 = Float64(t_0 * cosTheta)
	t_2 = sqrt(Float64(1.0 - Float64(cosTheta * 2.0)))
	tmp = 0.0
	if (t_1 != 0.0)
		tmp = Float64(t_1 / fma(Float64(Float64(t_2 / exp((cosTheta ^ 2.0))) / sqrt(pi)), t_0, Float64(Float64((c ^ 3.0) * cosTheta) + cosTheta)));
	else
		tmp = fma(Float64(t_2 / Float64(sqrt(pi) * cosTheta)), exp(Float64(-(cosTheta ^ 2.0))), Float64(c - -1.0)) ^ -1.0;
	end
	return tmp
end
code[cosTheta_, c_] := N[(1.0 / N[(N[(1.0 + c), $MachinePrecision] + N[(N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(N[(1.0 - cosTheta), $MachinePrecision] - cosTheta), $MachinePrecision]], $MachinePrecision] / cosTheta), $MachinePrecision]), $MachinePrecision] * N[Exp[N[((-cosTheta) * cosTheta), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[cosTheta_, c_] := Block[{t$95$0 = N[(c * c + N[(1.0 - c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * cosTheta), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(1.0 - N[(cosTheta * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Unequal[t$95$1, 0.0], N[(t$95$1 / N[(N[(N[(t$95$2 / N[Exp[N[Power[cosTheta, 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * t$95$0 + N[(N[(N[Power[c, 3.0], $MachinePrecision] * cosTheta), $MachinePrecision] + cosTheta), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(N[(t$95$2 / N[(N[Sqrt[Pi], $MachinePrecision] * cosTheta), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[Power[cosTheta, 2.0], $MachinePrecision])], $MachinePrecision] + N[(c - -1.0), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]]]]]
\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 := \mathsf{fma}\left(c, c, 1 - c\right)\\
t_1 := t_0 \cdot cosTheta\\
t_2 := \sqrt{1 - cosTheta \cdot 2}\\
\mathbf{if}\;t_1 \ne 0:\\
\;\;\;\;\frac{t_1}{\mathsf{fma}\left(\frac{\frac{t_2}{e^{{cosTheta}^{2}}}}{\sqrt{\pi}}, t_0, {c}^{3} \cdot cosTheta + cosTheta\right)}\\

\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{fma}\left(\frac{t_2}{\sqrt{\pi} \cdot cosTheta}, e^{-{cosTheta}^{2}}, c - -1\right)\right)}^{-1}\\


\end{array}

Error?

Derivation?

  1. Initial program 0.4

    \[\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 egg-rr0.3

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

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\mathsf{fma}\left(c, c, 1 - c\right) \cdot cosTheta \ne 0:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left({c}^{3} + 1, cosTheta, \mathsf{fma}\left(c, c, 1 - c\right) \cdot \frac{\frac{\sqrt{-\mathsf{fma}\left(2, cosTheta, -1\right)}}{e^{{cosTheta}^{2}}}}{\sqrt{\pi}}\right)} \cdot \left(\mathsf{fma}\left(c, c, 1 - c\right) \cdot cosTheta\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(\mathsf{fma}\left(\frac{\sqrt{-\mathsf{fma}\left(2, cosTheta, -1\right)}}{cosTheta \cdot \sqrt{\pi}}, e^{-{cosTheta}^{2}}, c + 1\right)\right)}^{-1}\\ } \end{array}} \]
  4. Simplified0.1

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\mathsf{fma}\left(c, c, 1 - c\right) \cdot cosTheta \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, c, 1 - c\right) \cdot cosTheta}{\mathsf{fma}\left(\frac{\frac{\sqrt{1 - cosTheta \cdot 2}}{e^{{cosTheta}^{2}}}}{\sqrt{\pi}}, \mathsf{fma}\left(c, c, 1 - c\right), {c}^{3} \cdot cosTheta + cosTheta\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(\mathsf{fma}\left(\frac{\sqrt{1 - cosTheta \cdot 2}}{\sqrt{\pi} \cdot cosTheta}, e^{-{cosTheta}^{2}}, c - -1\right)\right)}^{-1}\\ } \end{array}} \]
    Proof

Alternatives

Alternative 1
Error0.2
Cost52612
\[\begin{array}{l} t_0 := \sqrt{1 - cosTheta \cdot 2}\\ t_1 := {\left(\sqrt{\pi}\right)}^{-1}\\ \frac{1}{\left(1 + c\right) + \begin{array}{l} \mathbf{if}\;t_1 \ne 0:\\ \;\;\;\;\frac{t_0}{\frac{cosTheta}{t_1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{\sqrt{\pi} \cdot cosTheta}\\ \end{array} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \end{array} \]
Alternative 2
Error0.3
Cost26816
\[\frac{1}{\left(1 + c\right) + \frac{\frac{\sqrt{1 - cosTheta \cdot 2}}{\sqrt{\pi}}}{cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
Alternative 3
Error0.8
Cost20672
\[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \left(\left(-0.5 \cdot cosTheta + \frac{1}{cosTheta}\right) - 1\right)\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
Alternative 4
Error0.9
Cost20544
\[\frac{1}{\left(1 + c\right) + \frac{\left(-0.5 \cdot cosTheta + \frac{1}{cosTheta}\right) - 1}{\sqrt{\pi}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
Alternative 5
Error1.0
Cost20416
\[\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \left(\frac{1}{cosTheta} - 1\right)\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
Alternative 6
Error1.1
Cost20288
\[\frac{1}{\left(1 + c\right) + \frac{\frac{1}{cosTheta} - 1}{\sqrt{\pi}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
Alternative 7
Error1.5
Cost20160
\[\frac{1}{\left(1 + c\right) + \frac{\frac{1}{\sqrt{\pi}}}{cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}} \]
Alternative 8
Error1.7
Cost12928
\[\sqrt{\pi} \cdot cosTheta \]
Alternative 9
Error60.6
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (cosTheta c)
  :name "Beckmann Sample, normalization factor"
  :precision binary64
  :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))))))