
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
return x + (((y - x) * 6.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) * z)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
def code(x, y, z): return x + (((y - x) * 6.0) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\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) z)))
double code(double x, double y, double z) {
return x + (((y - x) * 6.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) * z)
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * z);
}
def code(x, y, z): return x + (((y - x) * 6.0) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z)) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (+ (* z (* 6.0 (- y x))) x))
double code(double x, double y, double z) {
return (z * (6.0 * (y - x))) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * (6.0d0 * (y - x))) + x
end function
public static double code(double x, double y, double z) {
return (z * (6.0 * (y - x))) + x;
}
def code(x, y, z): return (z * (6.0 * (y - x))) + x
function code(x, y, z) return Float64(Float64(z * Float64(6.0 * Float64(y - x))) + x) end
function tmp = code(x, y, z) tmp = (z * (6.0 * (y - x))) + x; end
code[x_, y_, z_] := N[(N[(z * N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(6 \cdot \left(y - x\right)\right) + x
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z -1000000000.0) (* (* z 6.0) (- y x)) (if (<= z 0.000225) (fma (* 6.0 y) z x) (* (* z (- y x)) 6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1000000000.0) {
tmp = (z * 6.0) * (y - x);
} else if (z <= 0.000225) {
tmp = fma((6.0 * y), z, x);
} else {
tmp = (z * (y - x)) * 6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1000000000.0) tmp = Float64(Float64(z * 6.0) * Float64(y - x)); elseif (z <= 0.000225) tmp = fma(Float64(6.0 * y), z, x); else tmp = Float64(Float64(z * Float64(y - x)) * 6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1000000000.0], N[(N[(z * 6.0), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.000225], N[(N[(6.0 * y), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1000000000:\\
\;\;\;\;\left(z \cdot 6\right) \cdot \left(y - x\right)\\
\mathbf{elif}\;z \leq 0.000225:\\
\;\;\;\;\mathsf{fma}\left(6 \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot \left(y - x\right)\right) \cdot 6\\
\end{array}
\end{array}
if z < -1e9Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.7
Applied rewrites99.7%
Applied rewrites99.8%
if -1e9 < z < 2.2499999999999999e-4Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6498.6
Applied rewrites98.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6498.6
Applied rewrites98.6%
if 2.2499999999999999e-4 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.9
Applied rewrites98.9%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (<= z -1000000000.0) (* z (* 6.0 (- y x))) (if (<= z 0.000225) (fma (* 6.0 y) z x) (* (* z (- y x)) 6.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1000000000.0) {
tmp = z * (6.0 * (y - x));
} else if (z <= 0.000225) {
tmp = fma((6.0 * y), z, x);
} else {
tmp = (z * (y - x)) * 6.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1000000000.0) tmp = Float64(z * Float64(6.0 * Float64(y - x))); elseif (z <= 0.000225) tmp = fma(Float64(6.0 * y), z, x); else tmp = Float64(Float64(z * Float64(y - x)) * 6.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1000000000.0], N[(z * N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.000225], N[(N[(6.0 * y), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1000000000:\\
\;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\
\mathbf{elif}\;z \leq 0.000225:\\
\;\;\;\;\mathsf{fma}\left(6 \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot \left(y - x\right)\right) \cdot 6\\
\end{array}
\end{array}
if z < -1e9Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.7
Applied rewrites99.7%
Applied rewrites99.7%
if -1e9 < z < 2.2499999999999999e-4Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6498.6
Applied rewrites98.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6498.6
Applied rewrites98.6%
if 2.2499999999999999e-4 < z Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.9
Applied rewrites98.9%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (* 6.0 (- y x))))) (if (<= z -1000000000.0) t_0 (if (<= z 0.000225) (fma (* 6.0 y) z x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (6.0 * (y - x));
double tmp;
if (z <= -1000000000.0) {
tmp = t_0;
} else if (z <= 0.000225) {
tmp = fma((6.0 * y), z, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * Float64(6.0 * Float64(y - x))) tmp = 0.0 if (z <= -1000000000.0) tmp = t_0; elseif (z <= 0.000225) tmp = fma(Float64(6.0 * y), z, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1000000000.0], t$95$0, If[LessEqual[z, 0.000225], N[(N[(6.0 * y), $MachinePrecision] * z + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(6 \cdot \left(y - x\right)\right)\\
\mathbf{if}\;z \leq -1000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.000225:\\
\;\;\;\;\mathsf{fma}\left(6 \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1e9 or 2.2499999999999999e-4 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.3
Applied rewrites99.3%
Applied rewrites99.3%
if -1e9 < z < 2.2499999999999999e-4Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6498.6
Applied rewrites98.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6498.6
Applied rewrites98.6%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (* 6.0 y) z x))) (if (<= y -6.5e-53) t_0 (if (<= y 3.2e-55) (fma (* -6.0 x) z x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((6.0 * y), z, x);
double tmp;
if (y <= -6.5e-53) {
tmp = t_0;
} else if (y <= 3.2e-55) {
tmp = fma((-6.0 * x), z, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(6.0 * y), z, x) tmp = 0.0 if (y <= -6.5e-53) tmp = t_0; elseif (y <= 3.2e-55) tmp = fma(Float64(-6.0 * x), z, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(6.0 * y), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[y, -6.5e-53], t$95$0, If[LessEqual[y, 3.2e-55], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(6 \cdot y, z, x\right)\\
\mathbf{if}\;y \leq -6.5 \cdot 10^{-53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-55}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6.4999999999999997e-53 or 3.2000000000000001e-55 < y Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6488.8
Applied rewrites88.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6488.8
Applied rewrites88.8%
if -6.4999999999999997e-53 < y < 3.2000000000000001e-55Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6455.7
Applied rewrites55.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6455.7
Applied rewrites55.7%
Taylor expanded in y around 0
lower-*.f6492.6
Applied rewrites92.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (* -6.0 x) z x))) (if (<= x -1.32e-126) t_0 (if (<= x 5.4e-155) (* (* 6.0 y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((-6.0 * x), z, x);
double tmp;
if (x <= -1.32e-126) {
tmp = t_0;
} else if (x <= 5.4e-155) {
tmp = (6.0 * y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(-6.0 * x), z, x) tmp = 0.0 if (x <= -1.32e-126) tmp = t_0; elseif (x <= 5.4e-155) tmp = Float64(Float64(6.0 * y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[x, -1.32e-126], t$95$0, If[LessEqual[x, 5.4e-155], N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{if}\;x \leq -1.32 \cdot 10^{-126}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.4 \cdot 10^{-155}:\\
\;\;\;\;\left(6 \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.31999999999999992e-126 or 5.39999999999999962e-155 < x Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6469.1
Applied rewrites69.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6469.1
Applied rewrites69.1%
Taylor expanded in y around 0
lower-*.f6479.8
Applied rewrites79.8%
if -1.31999999999999992e-126 < x < 5.39999999999999962e-155Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6483.6
Applied rewrites83.6%
Applied rewrites83.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (* z x) -6.0 x))) (if (<= x -1.32e-126) t_0 (if (<= x 5.4e-155) (* (* 6.0 y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((z * x), -6.0, x);
double tmp;
if (x <= -1.32e-126) {
tmp = t_0;
} else if (x <= 5.4e-155) {
tmp = (6.0 * y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(z * x), -6.0, x) tmp = 0.0 if (x <= -1.32e-126) tmp = t_0; elseif (x <= 5.4e-155) tmp = Float64(Float64(6.0 * y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * x), $MachinePrecision] * -6.0 + x), $MachinePrecision]}, If[LessEqual[x, -1.32e-126], t$95$0, If[LessEqual[x, 5.4e-155], N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(z \cdot x, -6, x\right)\\
\mathbf{if}\;x \leq -1.32 \cdot 10^{-126}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.4 \cdot 10^{-155}:\\
\;\;\;\;\left(6 \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.31999999999999992e-126 or 5.39999999999999962e-155 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6479.8
Applied rewrites79.8%
if -1.31999999999999992e-126 < x < 5.39999999999999962e-155Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6483.6
Applied rewrites83.6%
Applied rewrites83.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* 6.0 y) z))) (if (<= y -6.5e-53) t_0 (if (<= y 1.3e-44) (* (* -6.0 x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (6.0 * y) * z;
double tmp;
if (y <= -6.5e-53) {
tmp = t_0;
} else if (y <= 1.3e-44) {
tmp = (-6.0 * x) * z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (6.0d0 * y) * z
if (y <= (-6.5d-53)) then
tmp = t_0
else if (y <= 1.3d-44) then
tmp = ((-6.0d0) * x) * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (6.0 * y) * z;
double tmp;
if (y <= -6.5e-53) {
tmp = t_0;
} else if (y <= 1.3e-44) {
tmp = (-6.0 * x) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (6.0 * y) * z tmp = 0 if y <= -6.5e-53: tmp = t_0 elif y <= 1.3e-44: tmp = (-6.0 * x) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(6.0 * y) * z) tmp = 0.0 if (y <= -6.5e-53) tmp = t_0; elseif (y <= 1.3e-44) tmp = Float64(Float64(-6.0 * x) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (6.0 * y) * z; tmp = 0.0; if (y <= -6.5e-53) tmp = t_0; elseif (y <= 1.3e-44) tmp = (-6.0 * x) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -6.5e-53], t$95$0, If[LessEqual[y, 1.3e-44], N[(N[(-6.0 * x), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(6 \cdot y\right) \cdot z\\
\mathbf{if}\;y \leq -6.5 \cdot 10^{-53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-44}:\\
\;\;\;\;\left(-6 \cdot x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6.4999999999999997e-53 or 1.2999999999999999e-44 < y Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6461.3
Applied rewrites61.3%
Applied rewrites61.4%
if -6.4999999999999997e-53 < y < 1.2999999999999999e-44Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.2
Applied rewrites52.2%
Taylor expanded in y around 0
Applied rewrites46.2%
Applied rewrites46.3%
(FPCore (x y z) :precision binary64 (fma (* z (- y x)) 6.0 x))
double code(double x, double y, double z) {
return fma((z * (y - x)), 6.0, x);
}
function code(x, y, z) return fma(Float64(z * Float64(y - x)), 6.0, x) end
code[x_, y_, z_] := N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * 6.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot \left(y - x\right), 6, x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (* (* -6.0 x) z))
double code(double x, double y, double z) {
return (-6.0 * x) * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((-6.0d0) * x) * z
end function
public static double code(double x, double y, double z) {
return (-6.0 * x) * z;
}
def code(x, y, z): return (-6.0 * x) * z
function code(x, y, z) return Float64(Float64(-6.0 * x) * z) end
function tmp = code(x, y, z) tmp = (-6.0 * x) * z; end
code[x_, y_, z_] := N[(N[(-6.0 * x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(-6 \cdot x\right) \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.7
Applied rewrites63.7%
Taylor expanded in y around 0
Applied rewrites28.9%
Applied rewrites28.9%
(FPCore (x y z) :precision binary64 (- x (* (* 6.0 z) (- x y))))
double code(double x, double y, double z) {
return x - ((6.0 * z) * (x - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x - ((6.0d0 * z) * (x - y))
end function
public static double code(double x, double y, double z) {
return x - ((6.0 * z) * (x - y));
}
def code(x, y, z): return x - ((6.0 * z) * (x - y))
function code(x, y, z) return Float64(x - Float64(Float64(6.0 * z) * Float64(x - y))) end
function tmp = code(x, y, z) tmp = x - ((6.0 * z) * (x - y)); end
code[x_, y_, z_] := N[(x - N[(N[(6.0 * z), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(6 \cdot z\right) \cdot \left(x - y\right)
\end{array}
herbie shell --seed 2024244
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:alt
(! :herbie-platform default (- x (* (* 6 z) (- x y))))
(+ x (* (* (- y x) 6.0) z)))