?

Average Error: 0.0 → 0.0
Time: 2.8s
Precision: binary32
Cost: 224

?

\[\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 \]
\[1 - ux \cdot \left(1 - maxCos\right) \]
(FPCore (ux uy maxCos) :precision binary32 (+ (- 1.0 ux) (* ux maxCos)))
(FPCore (ux uy maxCos) :precision binary32 (- 1.0 (* ux (- 1.0 maxCos))))
float code(float ux, float uy, float maxCos) {
	return (1.0f - ux) + (ux * maxCos);
}
float code(float ux, float uy, float maxCos) {
	return 1.0f - (ux * (1.0f - maxCos));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = (1.0e0 - ux) + (ux * maxcos)
end function
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = 1.0e0 - (ux * (1.0e0 - maxcos))
end function
function code(ux, uy, maxCos)
	return Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos))
end
function code(ux, uy, maxCos)
	return Float32(Float32(1.0) - Float32(ux * Float32(Float32(1.0) - maxCos)))
end
function tmp = code(ux, uy, maxCos)
	tmp = (single(1.0) - ux) + (ux * maxCos);
end
function tmp = code(ux, uy, maxCos)
	tmp = single(1.0) - (ux * (single(1.0) - maxCos));
end
\left(1 - ux\right) + ux \cdot maxCos
1 - ux \cdot \left(1 - maxCos\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 0.0

    \[\left(1 - ux\right) + ux \cdot maxCos \]
  2. Taylor expanded in ux around 0 0.0

    \[\leadsto \color{blue}{1 + \left(maxCos - 1\right) \cdot ux} \]
  3. Simplified0.0

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

    [Start]0.0

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

    rational.json-simplify-17 [=>]0.0

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

    rational.json-simplify-2 [=>]0.0

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

    metadata-eval [<=]0.0

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

    rational.json-simplify-45 [<=]0.0

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

    rational.json-simplify-27 [<=]0.0

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

    rational.json-simplify-12 [<=]0.0

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

    rational.json-simplify-9 [<=]0.0

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

    rational.json-simplify-2 [<=]0.0

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

    metadata-eval [=>]0.0

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

    rational.json-simplify-1 [<=]0.0

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

    rational.json-simplify-12 [<=]0.0

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

    rational.json-simplify-9 [<=]0.0

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

    rational.json-simplify-43 [<=]0.0

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

    rational.json-simplify-2 [=>]0.0

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

    rational.json-simplify-9 [=>]0.0

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

    rational.json-simplify-12 [=>]0.0

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

    rational.json-simplify-42 [=>]0.0

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

    metadata-eval [=>]0.0

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

    rational.json-simplify-1 [=>]0.0

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

    rational.json-simplify-2 [=>]0.0

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

    rational.json-simplify-9 [=>]0.0

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

    rational.json-simplify-12 [=>]0.0

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

    metadata-eval [<=]0.0

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

    rational.json-simplify-27 [=>]0.0

    \[ 1 - ux \cdot \color{blue}{\left(1 - maxCos\right)} \]
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost224
\[\left(1 - ux\right) + ux \cdot maxCos \]
Alternative 2
Error0.6
Cost96
\[1 - ux \]
Alternative 3
Error9.1
Cost32
\[1 \]

Error

Reproduce?

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