
(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 (+ (fma (* (- x y) z) 6.0 (* 4.0 (- y x))) x))
double code(double x, double y, double z) {
return fma(((x - y) * z), 6.0, (4.0 * (y - x))) + x;
}
function code(x, y, z) return Float64(fma(Float64(Float64(x - y) * z), 6.0, Float64(4.0 * Float64(y - x))) + x) end
code[x_, y_, z_] := N[(N[(N[(N[(x - y), $MachinePrecision] * z), $MachinePrecision] * 6.0 + N[(4.0 * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(x - y\right) \cdot z, 6, 4 \cdot \left(y - x\right)\right) + x
\end{array}
Initial program 99.3%
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
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lift-/.f64N/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)))
(if (<= t_0 0.6666666666666)
(* (fma 6.0 z -3.0) x)
(if (<= t_0 4e+15) (fma (- y x) 4.0 x) (* (* y z) -6.0)))))
double code(double x, double y, double z) {
double t_0 = (2.0 / 3.0) - z;
double tmp;
if (t_0 <= 0.6666666666666) {
tmp = fma(6.0, z, -3.0) * x;
} else if (t_0 <= 4e+15) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = (y * z) * -6.0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(2.0 / 3.0) - z) tmp = 0.0 if (t_0 <= 0.6666666666666) tmp = Float64(fma(6.0, z, -3.0) * x); elseif (t_0 <= 4e+15) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(y * z) * -6.0); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[t$95$0, 0.6666666666666], N[(N[(6.0 * z + -3.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 4e+15], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(y * z), $MachinePrecision] * -6.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
\mathbf{if}\;t\_0 \leq 0.6666666666666:\\
\;\;\;\;\mathsf{fma}\left(6, z, -3\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -6\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.666666666666600016Initial program 99.7%
Taylor expanded in y around 0
metadata-evalN/A
cancel-sign-sub-invN/A
*-commutativeN/A
associate-*r*N/A
sub-negN/A
*-lft-identityN/A
distribute-rgt-neg-inN/A
neg-mul-1N/A
associate-*r*N/A
distribute-rgt-inN/A
metadata-evalN/A
distribute-rgt-inN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
neg-mul-1N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites64.6%
if 0.666666666666600016 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 4e15Initial program 98.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6498.1
Applied rewrites98.1%
if 4e15 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) Initial program 99.7%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.6
lift-+.f64N/A
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6499.7
Applied rewrites99.7%
Taylor expanded in y around inf
Applied rewrites63.0%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (<= z -0.59) (* (* (- y x) z) -6.0) (if (<= z 0.67) (fma (- y x) 4.0 x) (* (* -6.0 (- y x)) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.59) {
tmp = ((y - x) * z) * -6.0;
} else if (z <= 0.67) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = (-6.0 * (y - x)) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -0.59) tmp = Float64(Float64(Float64(y - x) * z) * -6.0); elseif (z <= 0.67) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(-6.0 * Float64(y - x)) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -0.59], N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * -6.0), $MachinePrecision], If[LessEqual[z, 0.67], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(-6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.59:\\
\;\;\;\;\left(\left(y - x\right) \cdot z\right) \cdot -6\\
\mathbf{elif}\;z \leq 0.67:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-6 \cdot \left(y - x\right)\right) \cdot z\\
\end{array}
\end{array}
if z < -0.589999999999999969Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6499.6
Applied rewrites99.6%
if -0.589999999999999969 < z < 0.67000000000000004Initial program 98.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.3
Applied rewrites97.3%
if 0.67000000000000004 < z Initial program 99.8%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.7
lift-+.f64N/A
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6498.8
Applied rewrites98.8%
Applied rewrites98.9%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* (- y x) z) -6.0))) (if (<= z -0.59) t_0 (if (<= z 0.67) (fma (- y x) 4.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = ((y - x) * z) * -6.0;
double tmp;
if (z <= -0.59) {
tmp = t_0;
} else if (z <= 0.67) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(Float64(y - x) * z) * -6.0) tmp = 0.0 if (z <= -0.59) tmp = t_0; elseif (z <= 0.67) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] * -6.0), $MachinePrecision]}, If[LessEqual[z, -0.59], t$95$0, If[LessEqual[z, 0.67], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(y - x\right) \cdot z\right) \cdot -6\\
\mathbf{if}\;z \leq -0.59:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.67:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -0.589999999999999969 or 0.67000000000000004 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6499.2
Applied rewrites99.2%
if -0.589999999999999969 < z < 0.67000000000000004Initial program 98.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.3
Applied rewrites97.3%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+15) (* (* y z) -6.0) (if (<= z 0.67) (fma (- y x) 4.0 x) (* (* z x) 6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+15) {
tmp = (y * z) * -6.0;
} else if (z <= 0.67) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = (z * x) * 6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+15) tmp = Float64(Float64(y * z) * -6.0); elseif (z <= 0.67) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(z * x) * 6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+15], N[(N[(y * z), $MachinePrecision] * -6.0), $MachinePrecision], If[LessEqual[z, 0.67], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+15}:\\
\;\;\;\;\left(y \cdot z\right) \cdot -6\\
\mathbf{elif}\;z \leq 0.67:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot x\right) \cdot 6\\
\end{array}
\end{array}
if z < -2.2e15Initial program 99.7%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.6
lift-+.f64N/A
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6499.7
Applied rewrites99.7%
Taylor expanded in y around inf
Applied rewrites63.0%
if -2.2e15 < z < 0.67000000000000004Initial program 98.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6496.6
Applied rewrites96.6%
if 0.67000000000000004 < z Initial program 99.8%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.7
lift-+.f64N/A
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6498.8
Applied rewrites98.8%
Taylor expanded in y around 0
Applied rewrites64.5%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* z x) 6.0))) (if (<= z -5.8) t_0 (if (<= z 0.67) (fma (- y x) 4.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z * x) * 6.0;
double tmp;
if (z <= -5.8) {
tmp = t_0;
} else if (z <= 0.67) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z * x) * 6.0) tmp = 0.0 if (z <= -5.8) tmp = t_0; elseif (z <= 0.67) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * x), $MachinePrecision] * 6.0), $MachinePrecision]}, If[LessEqual[z, -5.8], t$95$0, If[LessEqual[z, 0.67], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z \cdot x\right) \cdot 6\\
\mathbf{if}\;z \leq -5.8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.67:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.79999999999999982 or 0.67000000000000004 < z Initial program 99.7%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.6
lift-+.f64N/A
+-commutativeN/A
Applied rewrites99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6499.2
Applied rewrites99.2%
Taylor expanded in y around 0
Applied rewrites54.2%
if -5.79999999999999982 < z < 0.67000000000000004Initial program 98.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.3
Applied rewrites97.3%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (<= x -6.2e+63) (* -3.0 x) (if (<= x 3.5e-65) (* 4.0 y) (* -3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+63) {
tmp = -3.0 * x;
} else if (x <= 3.5e-65) {
tmp = 4.0 * y;
} else {
tmp = -3.0 * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-6.2d+63)) then
tmp = (-3.0d0) * x
else if (x <= 3.5d-65) then
tmp = 4.0d0 * y
else
tmp = (-3.0d0) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+63) {
tmp = -3.0 * x;
} else if (x <= 3.5e-65) {
tmp = 4.0 * y;
} else {
tmp = -3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.2e+63: tmp = -3.0 * x elif x <= 3.5e-65: tmp = 4.0 * y else: tmp = -3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.2e+63) tmp = Float64(-3.0 * x); elseif (x <= 3.5e-65) tmp = Float64(4.0 * y); else tmp = Float64(-3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.2e+63) tmp = -3.0 * x; elseif (x <= 3.5e-65) tmp = 4.0 * y; else tmp = -3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.2e+63], N[(-3.0 * x), $MachinePrecision], If[LessEqual[x, 3.5e-65], N[(4.0 * y), $MachinePrecision], N[(-3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+63}:\\
\;\;\;\;-3 \cdot x\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-65}:\\
\;\;\;\;4 \cdot y\\
\mathbf{else}:\\
\;\;\;\;-3 \cdot x\\
\end{array}
\end{array}
if x < -6.2000000000000001e63 or 3.50000000000000005e-65 < x Initial program 99.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6445.7
Applied rewrites45.7%
Taylor expanded in y around 0
Applied rewrites37.6%
if -6.2000000000000001e63 < x < 3.50000000000000005e-65Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.7
Applied rewrites55.7%
Taylor expanded in y around inf
Applied rewrites45.9%
Final simplification41.5%
(FPCore (x y z) :precision binary64 (fma (fma -6.0 z 4.0) (- y x) x))
double code(double x, double y, double z) {
return fma(fma(-6.0, z, 4.0), (y - x), x);
}
function code(x, y, z) return fma(fma(-6.0, z, 4.0), Float64(y - x), x) end
code[x_, y_, z_] := N[(N[(-6.0 * z + 4.0), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(-6, z, 4\right), y - x, x\right)
\end{array}
Initial program 99.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
neg-mul-1N/A
associate-*r*N/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lift-/.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (- y x) 4.0 x))
double code(double x, double y, double z) {
return fma((y - x), 4.0, x);
}
function code(x, y, z) return fma(Float64(y - x), 4.0, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, 4, x\right)
\end{array}
Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6450.3
Applied rewrites50.3%
(FPCore (x y z) :precision binary64 (* -3.0 x))
double code(double x, double y, double z) {
return -3.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-3.0d0) * x
end function
public static double code(double x, double y, double z) {
return -3.0 * x;
}
def code(x, y, z): return -3.0 * x
function code(x, y, z) return Float64(-3.0 * x) end
function tmp = code(x, y, z) tmp = -3.0 * x; end
code[x_, y_, z_] := N[(-3.0 * x), $MachinePrecision]
\begin{array}{l}
\\
-3 \cdot x
\end{array}
Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6450.3
Applied rewrites50.3%
Taylor expanded in y around 0
Applied rewrites25.5%
herbie shell --seed 2024235
(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))))