Trowbridge-Reitz Sample, near normal, slope_x

?

Percentage Accurate: 99.0% → 99.0%
Time: 13.4s
Precision: binary32
Cost: 9952

?

\[\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{u1}{1 - u1}} \cdot \cos \left(\sqrt{u2 \cdot \left(u2 \cdot 39.47841760436263\right)}\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 (/ u1 (- 1.0 u1))) (cos (sqrt (* u2 (* u2 39.47841760436263))))))
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((u1 / (1.0f - u1))) * cosf(sqrtf((u2 * (u2 * 39.47841760436263f))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * cos((6.28318530718e0 * u2))
end function
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * cos(sqrt((u2 * (u2 * 39.47841760436263e0))))
end function
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(u1 / Float32(Float32(1.0) - u1))) * cos(sqrt(Float32(u2 * Float32(u2 * Float32(39.47841760436263))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2));
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos(sqrt((u2 * (u2 * single(39.47841760436263)))));
end
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{u2 \cdot \left(u2 \cdot 39.47841760436263\right)}\right)

Local Percentage Accuracy?

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.

Herbie found 14 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 98.8%

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

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
    Step-by-step derivation

    [Start]98.8

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

    add-sqr-sqrt [=>]98.6

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

    pow1/2 [=>]98.6

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

    pow1/2 [=>]98.6

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

    pow-prod-down [=>]98.8

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

    swap-sqr [=>]98.7

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

    metadata-eval [=>]98.9

    \[ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(\color{blue}{39.47841760436263} \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right) \]
  3. Simplified98.9%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{u2 \cdot \left(u2 \cdot 39.47841760436263\right)}\right)} \]
    Step-by-step derivation

    [Start]98.9

    \[ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right) \]

    unpow1/2 [=>]98.9

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

    associate-*r* [=>]98.9

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

    *-commutative [=>]98.9

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

    *-commutative [=>]98.9

    \[ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{u2 \cdot \color{blue}{\left(u2 \cdot 39.47841760436263\right)}}\right) \]
  4. Final simplification98.9%

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

Alternatives

Alternative 1
Accuracy94.1%
Cost10020
\[\begin{array}{l} t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\ \mathbf{if}\;t_0 \leq 0.9879999756813049:\\ \;\;\;\;\sqrt{u1} \cdot \left(\left(1 + t_0\right) + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right)\\ \end{array} \]
Alternative 2
Accuracy94.1%
Cost9892
\[\begin{array}{l} t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\ \mathbf{if}\;t_0 \leq 0.9879999756813049:\\ \;\;\;\;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 3
Accuracy99.0%
Cost6688
\[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot 6.28318530718\right) \]
Alternative 4
Accuracy88.3%
Cost3616
\[\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right) \]
Alternative 5
Accuracy71.5%
Cost3360
\[\sqrt{u1 \cdot \left(u1 + 1\right)} \]
Alternative 6
Accuracy71.6%
Cost3360
\[\sqrt{u1 + u1 \cdot u1} \]
Alternative 7
Accuracy79.9%
Cost3360
\[\sqrt{\frac{u1}{1 - u1}} \]
Alternative 8
Accuracy63.2%
Cost3232
\[\sqrt{u1} \]
Alternative 9
Accuracy18.9%
Cost416
\[\left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right) \cdot \left(u1 \cdot \left(u1 + 0.5\right)\right) \]
Alternative 10
Accuracy18.9%
Cost416
\[\left(u1 + 0.5\right) \cdot \left(u1 + u1 \cdot \left(-19.739208802181317 \cdot \left(u2 \cdot u2\right)\right)\right) \]
Alternative 11
Accuracy18.6%
Cost224
\[u1 \cdot u1 + u1 \cdot 0.5 \]
Alternative 12
Accuracy18.6%
Cost160
\[u1 \cdot \left(u1 + 0.5\right) \]
Alternative 13
Accuracy18.3%
Cost96
\[u1 \cdot 0.5 \]

Reproduce?

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