?

Average Error: 0.3 → 0.3
Time: 11.5s
Precision: binary32
Cost: 10016

?

\[\left(\left(cosTheta_i > 0.9999 \land cosTheta_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
\[\sqrt{\frac{\mathsf{fma}\left(u1, u1, u1\right)}{1 - u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ (fma u1 u1 u1) (- 1.0 (* u1 u1)))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((6.28318530718f * u2));
}
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((fmaf(u1, u1, u1) / (1.0f - (u1 * u1)))) * cosf((6.28318530718f * u2));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2)))
end
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(fma(u1, u1, u1) / Float32(Float32(1.0) - Float32(u1 * u1)))) * cos(Float32(Float32(6.28318530718) * u2)))
end
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\sqrt{\frac{\mathsf{fma}\left(u1, u1, u1\right)}{1 - u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)

Error?

Derivation?

  1. Initial program 0.3

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  2. Applied egg-rr0.3

    \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1 \cdot u1} \cdot u1 + \frac{u1}{1 - u1 \cdot u1} \cdot 1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  3. Simplified0.3

    \[\leadsto \sqrt{\color{blue}{\frac{\mathsf{fma}\left(u1, u1, u1\right)}{1 - u1 \cdot u1}}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    Proof

    [Start]0.3

    \[ \sqrt{\frac{u1}{1 - u1 \cdot u1} \cdot u1 + \frac{u1}{1 - u1 \cdot u1} \cdot 1} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

    distribute-lft-in [<=]0.4

    \[ \sqrt{\color{blue}{\frac{u1}{1 - u1 \cdot u1} \cdot \left(u1 + 1\right)}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

    associate-*l/ [=>]0.4

    \[ \sqrt{\color{blue}{\frac{u1 \cdot \left(u1 + 1\right)}{1 - u1 \cdot u1}}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

    *-commutative [=>]0.4

    \[ \sqrt{\frac{\color{blue}{\left(u1 + 1\right) \cdot u1}}{1 - u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

    distribute-lft1-in [<=]0.3

    \[ \sqrt{\frac{\color{blue}{u1 \cdot u1 + u1}}{1 - u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

    fma-udef [<=]0.3

    \[ \sqrt{\frac{\color{blue}{\mathsf{fma}\left(u1, u1, u1\right)}}{1 - u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  4. Final simplification0.3

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(u1, u1, u1\right)}{1 - u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

Alternatives

Alternative 1
Error1.9
Cost9892
\[\begin{array}{l} t_0 := \cos \left(6.28318530718 \cdot u2\right)\\ \mathbf{if}\;t_0 \leq 0.9800000190734863:\\ \;\;\;\;t_0 \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right)\\ \end{array} \]
Alternative 2
Error0.3
Cost7072
\[\begin{array}{l} t_0 := \frac{u1}{1 - u1 \cdot u1}\\ \cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{t_0 + u1 \cdot t_0} \end{array} \]
Alternative 3
Error0.3
Cost6688
\[\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{\frac{u1}{1 - u1}} \]
Alternative 4
Error4.6
Cost3616
\[\sqrt{\frac{u1}{1 - u1} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -39.47841760436263\right)} \]
Alternative 5
Error3.7
Cost3616
\[\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right) \]
Alternative 6
Error9.0
Cost3360
\[\sqrt{u1 \cdot \left(u1 + 1\right)} \]
Alternative 7
Error6.3
Cost3360
\[\sqrt{\frac{u1}{1 - u1}} \]
Alternative 8
Error11.7
Cost3232
\[\sqrt{u1} \]

Error

Reproduce?

herbie shell --seed 2023053 
(FPCore (cosTheta_i u1 u2)
  :name "Trowbridge-Reitz Sample, near normal, slope_x"
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))