?

Average Error: 12.8 → 0.6
Time: 1.7min
Precision: binary32
Cost: 10756

?

\[\left(\left(\left(\left(0.0001 \leq alphax \land alphax \leq 1\right) \land \left(0.0001 \leq alphay \land alphay \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\right) \land \left(0 \leq cos2phi \land cos2phi \leq 1\right)\right) \land 0 \leq sin2phi\]
\[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;1 - u0 \leq 0.9599999785423279:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{\frac{\frac{cos2phi}{alphax}}{alphax}}{alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\left(\left(-u0\right) + \left(-0.3333333333333333 \cdot {u0}^{3} + \left(-0.5 \cdot {u0}^{2} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\frac{1}{alphax \cdot alphax} \cdot cos2phi + t_0}\\ \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- (log (- 1.0 u0)))
  (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (let* ((t_0 (/ sin2phi (* alphay alphay))))
   (if (<= (- 1.0 u0) 0.9599999785423279)
     (/
      (- (log (- 1.0 u0)))
      (+
       (*
        (* (* alphax alphax) (/ 1.0 alphax))
        (/ (/ (/ cos2phi alphax) alphax) alphax))
       t_0))
     (/
      (-
       (+
        (- u0)
        (+
         (* -0.3333333333333333 (pow u0 3.0))
         (+ (* -0.5 (pow u0 2.0)) (* -0.25 (pow u0 4.0))))))
      (+ (* (/ 1.0 (* alphax alphax)) cos2phi) t_0)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -logf((1.0f - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	float t_0 = sin2phi / (alphay * alphay);
	float tmp;
	if ((1.0f - u0) <= 0.9599999785423279f) {
		tmp = -logf((1.0f - u0)) / ((((alphax * alphax) * (1.0f / alphax)) * (((cos2phi / alphax) / alphax) / alphax)) + t_0);
	} else {
		tmp = -(-u0 + ((-0.3333333333333333f * powf(u0, 3.0f)) + ((-0.5f * powf(u0, 2.0f)) + (-0.25f * powf(u0, 4.0f))))) / (((1.0f / (alphax * alphax)) * cos2phi) + t_0);
	}
	return tmp;
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    real(4) :: t_0
    real(4) :: tmp
    t_0 = sin2phi / (alphay * alphay)
    if ((1.0e0 - u0) <= 0.9599999785423279e0) then
        tmp = -log((1.0e0 - u0)) / ((((alphax * alphax) * (1.0e0 / alphax)) * (((cos2phi / alphax) / alphax) / alphax)) + t_0)
    else
        tmp = -(-u0 + (((-0.3333333333333333e0) * (u0 ** 3.0e0)) + (((-0.5e0) * (u0 ** 2.0e0)) + ((-0.25e0) * (u0 ** 4.0e0))))) / (((1.0e0 / (alphax * alphax)) * cos2phi) + t_0)
    end if
    code = tmp
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log(Float32(Float32(1.0) - u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))))
end
function code(alphax, alphay, u0, cos2phi, sin2phi)
	t_0 = Float32(sin2phi / Float32(alphay * alphay))
	tmp = Float32(0.0)
	if (Float32(Float32(1.0) - u0) <= Float32(0.9599999785423279))
		tmp = Float32(Float32(-log(Float32(Float32(1.0) - u0))) / Float32(Float32(Float32(Float32(alphax * alphax) * Float32(Float32(1.0) / alphax)) * Float32(Float32(Float32(cos2phi / alphax) / alphax) / alphax)) + t_0));
	else
		tmp = Float32(Float32(-Float32(Float32(-u0) + Float32(Float32(Float32(-0.3333333333333333) * (u0 ^ Float32(3.0))) + Float32(Float32(Float32(-0.5) * (u0 ^ Float32(2.0))) + Float32(Float32(-0.25) * (u0 ^ Float32(4.0))))))) / Float32(Float32(Float32(Float32(1.0) / Float32(alphax * alphax)) * cos2phi) + t_0));
	end
	return tmp
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
end
function tmp_2 = code(alphax, alphay, u0, cos2phi, sin2phi)
	t_0 = sin2phi / (alphay * alphay);
	tmp = single(0.0);
	if ((single(1.0) - u0) <= single(0.9599999785423279))
		tmp = -log((single(1.0) - u0)) / ((((alphax * alphax) * (single(1.0) / alphax)) * (((cos2phi / alphax) / alphax) / alphax)) + t_0);
	else
		tmp = -(-u0 + ((single(-0.3333333333333333) * (u0 ^ single(3.0))) + ((single(-0.5) * (u0 ^ single(2.0))) + (single(-0.25) * (u0 ^ single(4.0)))))) / (((single(1.0) / (alphax * alphax)) * cos2phi) + t_0);
	end
	tmp_2 = tmp;
end
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\begin{array}{l}
t_0 := \frac{sin2phi}{alphay \cdot alphay}\\
\mathbf{if}\;1 - u0 \leq 0.9599999785423279:\\
\;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{\frac{\frac{cos2phi}{alphax}}{alphax}}{alphax} + t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{-\left(\left(-u0\right) + \left(-0.3333333333333333 \cdot {u0}^{3} + \left(-0.5 \cdot {u0}^{2} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\frac{1}{alphax \cdot alphax} \cdot cos2phi + t_0}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (-.f32 1 u0) < 0.959999979

    1. Initial program 1.5

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    2. Applied egg-rr1.5

      \[\leadsto \frac{-\log \left(1 - u0\right)}{\color{blue}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{\frac{\frac{cos2phi}{alphax}}{alphax}}{alphax}} + \frac{sin2phi}{alphay \cdot alphay}} \]

    if 0.959999979 < (-.f32 1 u0)

    1. Initial program 14.6

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    2. Taylor expanded in u0 around 0 0.5

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot u0 + \left(-0.5 \cdot {u0}^{2} + \left(-0.3333333333333333 \cdot {u0}^{3} + -0.25 \cdot {u0}^{4}\right)\right)\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    3. Simplified0.5

      \[\leadsto \frac{-\color{blue}{\left(\left(-u0\right) + \left(-0.3333333333333333 \cdot {u0}^{3} + \left(-0.5 \cdot {u0}^{2} + -0.25 \cdot {u0}^{4}\right)\right)\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
      Proof

      [Start]0.5

      \[ \frac{-\left(-1 \cdot u0 + \left(-0.5 \cdot {u0}^{2} + \left(-0.3333333333333333 \cdot {u0}^{3} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

      rational_best-simplify-1 [=>]0.5

      \[ \frac{-\left(\color{blue}{u0 \cdot -1} + \left(-0.5 \cdot {u0}^{2} + \left(-0.3333333333333333 \cdot {u0}^{3} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

      rational_best-simplify-10 [=>]0.5

      \[ \frac{-\left(\color{blue}{\left(-u0\right)} + \left(-0.5 \cdot {u0}^{2} + \left(-0.3333333333333333 \cdot {u0}^{3} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

      rational_best-simplify-47 [=>]0.5

      \[ \frac{-\left(\left(-u0\right) + \color{blue}{\left(-0.25 \cdot {u0}^{4} + \left(-0.3333333333333333 \cdot {u0}^{3} + -0.5 \cdot {u0}^{2}\right)\right)}\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

      rational_best-simplify-3 [<=]0.5

      \[ \frac{-\left(\left(-u0\right) + \left(-0.25 \cdot {u0}^{4} + \color{blue}{\left(-0.5 \cdot {u0}^{2} + -0.3333333333333333 \cdot {u0}^{3}\right)}\right)\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

      rational_best-simplify-47 [=>]0.5

      \[ \frac{-\left(\left(-u0\right) + \color{blue}{\left(-0.3333333333333333 \cdot {u0}^{3} + \left(-0.5 \cdot {u0}^{2} + -0.25 \cdot {u0}^{4}\right)\right)}\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    4. Applied egg-rr0.5

      \[\leadsto \frac{-\left(\left(-u0\right) + \left(-0.3333333333333333 \cdot {u0}^{3} + \left(-0.5 \cdot {u0}^{2} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\color{blue}{\frac{1}{alphax \cdot alphax} \cdot cos2phi} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9599999785423279:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{\frac{\frac{cos2phi}{alphax}}{alphax}}{alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\left(\left(-u0\right) + \left(-0.3333333333333333 \cdot {u0}^{3} + \left(-0.5 \cdot {u0}^{2} + -0.25 \cdot {u0}^{4}\right)\right)\right)}{\frac{1}{alphax \cdot alphax} \cdot cos2phi + \frac{sin2phi}{alphay \cdot alphay}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.6
Cost10628
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;1 - u0 \leq 0.9599999785423279:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{\frac{\frac{cos2phi}{alphax}}{alphax}}{alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{u0 + \left(0.5 \cdot {u0}^{2} - \left({u0}^{3} \cdot -0.3333333333333333 + {u0}^{4} \cdot -0.25\right)\right)}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \end{array} \]
Alternative 2
Error0.7
Cost7332
\[\begin{array}{l} t_0 := \frac{\frac{cos2phi}{alphax}}{alphax}\\ t_1 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;1 - u0 \leq 0.9850000143051147:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{t_0}{alphax} + t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-u0\right) + \left(-0.5 \cdot {u0}^{2} + -0.3333333333333333 \cdot {u0}^{3}\right)}{-\left(t_0 + t_1\right)}\\ \end{array} \]
Alternative 3
Error1.2
Cost7268
\[\begin{array}{l} t_0 := \log \left(1 - u0\right)\\ t_1 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;-t_0 \leq 0.0031999999191612005:\\ \;\;\;\;\frac{\left(-u0\right) + -0.5 \cdot {u0}^{2}}{-\left(\frac{\frac{cos2phi}{alphax}}{alphax} + t_1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{-\left(\frac{\frac{cos2phi}{alphax \cdot \frac{1}{alphax}}}{alphax \cdot alphax} + t_1\right)}\\ \end{array} \]
Alternative 4
Error1.2
Cost7204
\[\begin{array}{l} t_0 := -\log \left(1 - u0\right)\\ t_1 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 0.0031999999191612005:\\ \;\;\;\;\frac{-\left(\left(-u0\right) + -0.5 \cdot {u0}^{2}\right)}{\frac{cos2phi}{alphax \cdot alphax} + t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{\left(\frac{1}{alphax} \cdot \frac{1}{alphax}\right) \cdot cos2phi + t_1}\\ \end{array} \]
Alternative 5
Error1.2
Cost7204
\[\begin{array}{l} t_0 := -\log \left(1 - u0\right)\\ t_1 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 0.0031999999191612005:\\ \;\;\;\;\frac{\left(-u0\right) + -0.5 \cdot {u0}^{2}}{-\left(\frac{\frac{cos2phi}{alphax}}{alphax} + t_1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{\left(\frac{1}{alphax} \cdot \frac{1}{alphax}\right) \cdot cos2phi + t_1}\\ \end{array} \]
Alternative 6
Error1.2
Cost4164
\[\begin{array}{l} t_0 := \frac{\frac{cos2phi}{alphax}}{alphax}\\ t_1 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;1 - u0 \leq 0.9965999722480774:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\left(alphax \cdot alphax\right) \cdot \frac{1}{alphax}\right) \cdot \frac{t_0}{alphax} + t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-u0\right) + -0.5 \cdot {u0}^{2}}{-\left(t_0 + t_1\right)}\\ \end{array} \]
Alternative 7
Error3.2
Cost3972
\[\begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9998599886894226:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(\frac{1}{alphax} \cdot \frac{1}{alphax}\right) \cdot cos2phi + \frac{sin2phi}{alphay \cdot alphay}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-u0}{-\left(\frac{\frac{cos2phi}{alphax}}{alphax} + \left(sin2phi \cdot 4\right) \cdot \frac{\frac{1}{alphay}}{\left(alphay + alphay\right) \cdot 2}\right)}\\ \end{array} \]
Alternative 8
Error3.2
Cost3908
\[\begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9998599886894226:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax} \cdot \frac{1}{alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-u0}{-\left(\frac{\frac{cos2phi}{alphax}}{alphax} + \left(sin2phi \cdot 4\right) \cdot \frac{\frac{1}{alphay}}{\left(alphay + alphay\right) \cdot 2}\right)}\\ \end{array} \]
Alternative 9
Error3.2
Cost3844
\[\begin{array}{l} t_0 := \frac{\frac{cos2phi}{alphax}}{alphax}\\ \mathbf{if}\;1 - u0 \leq 0.9998599886894226:\\ \;\;\;\;\frac{\log \left(1 - u0\right)}{-\left(t_0 + \frac{sin2phi}{alphay \cdot alphay}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-u0}{-\left(t_0 + \left(sin2phi \cdot 4\right) \cdot \frac{\frac{1}{alphay}}{\left(alphay + alphay\right) \cdot 2}\right)}\\ \end{array} \]
Alternative 10
Error7.6
Cost736
\[\frac{-u0}{-\left(\frac{\frac{cos2phi}{alphax}}{alphax} + \left(sin2phi \cdot 4\right) \cdot \frac{\frac{1}{alphay}}{\left(alphay + alphay\right) \cdot 2}\right)} \]
Alternative 11
Error7.6
Cost544
\[\frac{u0}{\frac{\frac{cos2phi}{alphax}}{alphax} + \frac{sin2phi}{alphay} \cdot \frac{alphay}{alphay \cdot alphay}} \]
Alternative 12
Error7.6
Cost480
\[\frac{u0}{\frac{\frac{cos2phi}{alphax}}{alphax} + \frac{1}{alphay \cdot alphay} \cdot sin2phi} \]
Alternative 13
Error7.6
Cost480
\[\frac{u0}{\frac{\frac{cos2phi}{alphax}}{alphax} + \frac{sin2phi}{alphay} \cdot \frac{1}{alphay}} \]
Alternative 14
Error7.6
Cost416
\[\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
Alternative 15
Error7.6
Cost416
\[\frac{u0}{\frac{\frac{cos2phi}{alphax}}{alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

Error

Reproduce?

herbie shell --seed 2023099 
(FPCore (alphax alphay u0 cos2phi sin2phi)
  :name "Beckmann Distribution sample, tan2theta, alphax != alphay, u1 <= 0.5"
  :precision binary32
  :pre (and (and (and (and (and (<= 0.0001 alphax) (<= alphax 1.0)) (and (<= 0.0001 alphay) (<= alphay 1.0))) (and (<= 2.328306437e-10 u0) (<= u0 1.0))) (and (<= 0.0 cos2phi) (<= cos2phi 1.0))) (<= 0.0 sin2phi))
  (/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))