
(FPCore (ux uy maxCos)
: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)))float code(float ux, float uy, float maxCos) {
return (1.0f - ux) + (ux * maxCos);
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = (1.0e0 - ux) + (ux * maxcos)
end function
function code(ux, uy, maxCos) return Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) end
function tmp = code(ux, uy, maxCos) tmp = (single(1.0) - ux) + (ux * maxCos); end
\left(1 - ux\right) + ux \cdot maxCos
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos)
: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)))float code(float ux, float uy, float maxCos) {
return (1.0f - ux) + (ux * maxCos);
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = (1.0e0 - ux) + (ux * maxcos)
end function
function code(ux, uy, maxCos) return Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) end
function tmp = code(ux, uy, maxCos) tmp = (single(1.0) - ux) + (ux * maxCos); end
\left(1 - ux\right) + ux \cdot maxCos
(FPCore (ux uy maxCos)
: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)))
(- (- (* maxCos ux) ux) -1.0))float code(float ux, float uy, float maxCos) {
return ((maxCos * ux) - ux) - -1.0f;
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = ((maxcos * ux) - ux) - (-1.0e0)
end function
function code(ux, uy, maxCos) return Float32(Float32(Float32(maxCos * ux) - ux) - Float32(-1.0)) end
function tmp = code(ux, uy, maxCos) tmp = ((maxCos * ux) - ux) - single(-1.0); end
\left(maxCos \cdot ux - ux\right) - -1
Initial program 99.9%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
sub-negate-revN/A
add-flip-revN/A
+-commutativeN/A
add-flip-revN/A
lower--.f32N/A
remove-double-negN/A
lift-*.f32N/A
distribute-lft-neg-outN/A
lower--.f32N/A
distribute-lft-neg-outN/A
lift-*.f32N/A
remove-double-negN/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-eval99.9%
Applied rewrites99.9%
(FPCore (ux uy maxCos)
: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)))
(fma ux maxCos (- 1.0 ux)))float code(float ux, float uy, float maxCos) {
return fmaf(ux, maxCos, (1.0f - ux));
}
function code(ux, uy, maxCos) return fma(ux, maxCos, Float32(Float32(1.0) - ux)) end
\mathsf{fma}\left(ux, maxCos, 1 - ux\right)
Initial program 99.9%
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
lower-fma.f3299.9%
Applied rewrites99.9%
(FPCore (ux uy maxCos)
: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)))
(- (fma maxCos ux 1.0) ux))float code(float ux, float uy, float maxCos) {
return fmaf(maxCos, ux, 1.0f) - ux;
}
function code(ux, uy, maxCos) return Float32(fma(maxCos, ux, Float32(1.0)) - ux) end
\mathsf{fma}\left(maxCos, ux, 1\right) - ux
Initial program 99.9%
lift-+.f32N/A
lift-*.f32N/A
fp-cancel-sign-sub-invN/A
sub-flipN/A
+-commutativeN/A
lift--.f32N/A
associate--l+N/A
lower--.f32N/A
distribute-lft-neg-outN/A
lift-*.f32N/A
remove-double-negN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f3299.8%
Applied rewrites99.8%
(FPCore (ux uy maxCos)
: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))float code(float ux, float uy, float maxCos) {
return 1.0f - ux;
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 1.0e0 - ux
end function
function code(ux, uy, maxCos) return Float32(Float32(1.0) - ux) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0) - ux; end
1 - ux
Initial program 99.9%
Taylor expanded in maxCos around 0
lower--.f3298.1%
Applied rewrites98.1%
(FPCore (ux uy maxCos)
: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)float code(float ux, float uy, float maxCos) {
return 1.0f;
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 1.0e0
end function
function code(ux, uy, maxCos) return Float32(1.0) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0); end
1
Initial program 99.9%
Taylor expanded in maxCos around 0
lower--.f3298.1%
Applied rewrites98.1%
Taylor expanded in ux around 0
Applied rewrites71.4%
herbie shell --seed 2025356
(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)))