UniformSampleCone, z

?

Percentage Accurate: 99.9% → 99.9%
Time: 4.6s
Precision: binary32
Cost: 3360

?

\[\left(\left(2.328306437 \cdot 10^{-10} \leq ux \land ux \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq uy \land uy \leq 1\right)\right) \land \left(0 \leq maxCos \land maxCos \leq 1\right)\]
\[\left(1 - ux\right) + ux \cdot maxCos \]
\[\mathsf{fma}\left(ux, maxCos + -1, 1\right) \]
(FPCore (ux uy maxCos) :precision binary32 (+ (- 1.0 ux) (* ux maxCos)))
(FPCore (ux uy maxCos) :precision binary32 (fma ux (+ maxCos -1.0) 1.0))
float code(float ux, float uy, float maxCos) {
	return (1.0f - ux) + (ux * maxCos);
}
float code(float ux, float uy, float maxCos) {
	return fmaf(ux, (maxCos + -1.0f), 1.0f);
}
function code(ux, uy, maxCos)
	return Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos))
end
function code(ux, uy, maxCos)
	return fma(ux, Float32(maxCos + Float32(-1.0)), Float32(1.0))
end
\left(1 - ux\right) + ux \cdot maxCos
\mathsf{fma}\left(ux, maxCos + -1, 1\right)

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.

Herbie found 5 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Derivation?

  1. Initial program 99.9%

    \[\left(1 - ux\right) + ux \cdot maxCos \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(ux, maxCos + -1, 1\right)} \]
    Step-by-step derivation

    [Start]99.9%

    \[ \left(1 - ux\right) + ux \cdot maxCos \]

    sub-neg [=>]99.9%

    \[ \color{blue}{\left(1 + \left(-ux\right)\right)} + ux \cdot maxCos \]

    associate-+l+ [=>]100.0%

    \[ \color{blue}{1 + \left(\left(-ux\right) + ux \cdot maxCos\right)} \]

    +-commutative [=>]100.0%

    \[ \color{blue}{\left(\left(-ux\right) + ux \cdot maxCos\right) + 1} \]

    neg-mul-1 [=>]100.0%

    \[ \left(\color{blue}{-1 \cdot ux} + ux \cdot maxCos\right) + 1 \]

    *-commutative [=>]100.0%

    \[ \left(-1 \cdot ux + \color{blue}{maxCos \cdot ux}\right) + 1 \]

    distribute-rgt-out [=>]100.0%

    \[ \color{blue}{ux \cdot \left(-1 + maxCos\right)} + 1 \]

    fma-def [=>]100.0%

    \[ \color{blue}{\mathsf{fma}\left(ux, -1 + maxCos, 1\right)} \]

    +-commutative [=>]100.0%

    \[ \mathsf{fma}\left(ux, \color{blue}{maxCos + -1}, 1\right) \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(ux, maxCos + -1, 1\right) \]

Alternatives

Alternative 1
Accuracy99.9%
Cost3360
\[\mathsf{fma}\left(ux, maxCos + -1, 1\right) \]
Alternative 2
Accuracy99.9%
Cost224
\[\left(1 - ux\right) + ux \cdot maxCos \]
Alternative 3
Accuracy99.9%
Cost224
\[1 + ux \cdot \left(maxCos + -1\right) \]
Alternative 4
Accuracy98.1%
Cost96
\[1 - ux \]
Alternative 5
Accuracy71.3%
Cost32
\[1 \]

Reproduce?

herbie shell --seed 2023229 
(FPCore (ux uy maxCos)
  :name "UniformSampleCone, z"
  :precision binary32
  :pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
  (+ (- 1.0 ux) (* ux maxCos)))