
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (((y - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (fma (* z (- x y)) 6.0 (* (- y x) 4.0))))
double code(double x, double y, double z) {
return x + fma((z * (x - y)), 6.0, ((y - x) * 4.0));
}
function code(x, y, z) return Float64(x + fma(Float64(z * Float64(x - y)), 6.0, Float64(Float64(y - x) * 4.0))) end
code[x_, y_, z_] := N[(x + N[(N[(z * N[(x - y), $MachinePrecision]), $MachinePrecision] * 6.0 + N[(N[(y - x), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(z \cdot \left(x - y\right), 6, \left(y - x\right) \cdot 4\right)
\end{array}
Initial program 99.6%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-/.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* z (* 6.0 (- x y))))) (if (<= t_0 -400000.0) t_1 (if (<= t_0 1.0) (fma 4.0 (- y x) x) t_1))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double t_1 = z * (6.0 * (x - y));
double tmp;
if (t_0 <= -400000.0) {
tmp = t_1;
} else if (t_0 <= 1.0) {
tmp = fma(4.0, (y - x), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) t_1 = Float64(z * Float64(6.0 * Float64(x - y))) tmp = 0.0 if (t_0 <= -400000.0) tmp = t_1; elseif (t_0 <= 1.0) tmp = fma(4.0, Float64(y - x), x); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(6.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -400000.0], t$95$1, If[LessEqual[t$95$0, 1.0], N[(4.0 * N[(y - x), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := z \cdot \left(6 \cdot \left(x - y\right)\right)\\
\mathbf{if}\;t\_0 \leq -400000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\mathsf{fma}\left(4, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < -4e5 or 1 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.7%
Taylor expanded in z around inf
metadata-evalN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
neg-mul-1N/A
lower-*.f64N/A
sub-negN/A
neg-mul-1N/A
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
mul-1-negN/A
sub-negN/A
lower--.f6498.3
Applied rewrites98.3%
Applied rewrites98.3%
if -4e5 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 1Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lower--.f6496.8
Applied rewrites96.8%
Final simplification97.6%
herbie shell --seed 2024223
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
:precision binary64
(+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))