
(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 (fma (- y x) (* z 6.0) x))
double code(double x, double y, double z) {
return fma((y - x), (z * 6.0), x);
}
function code(x, y, z) return fma(Float64(y - x), Float64(z * 6.0), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(z * 6.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z \cdot 6, x\right)
\end{array}
Initial program 99.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.165) (not (<= z 0.00012))) (* (* 6.0 (- y x)) z) (fma (* z y) 6.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.165) || !(z <= 0.00012)) {
tmp = (6.0 * (y - x)) * z;
} else {
tmp = fma((z * y), 6.0, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.165) || !(z <= 0.00012)) tmp = Float64(Float64(6.0 * Float64(y - x)) * z); else tmp = fma(Float64(z * y), 6.0, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.165], N[Not[LessEqual[z, 0.00012]], $MachinePrecision]], N[(N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(N[(z * y), $MachinePrecision] * 6.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.165 \lor \neg \left(z \leq 0.00012\right):\\
\;\;\;\;\left(6 \cdot \left(y - x\right)\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, 6, x\right)\\
\end{array}
\end{array}
if z < -0.165000000000000008 or 1.20000000000000003e-4 < z Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6451.8
Applied rewrites51.8%
Applied rewrites52.7%
Taylor expanded in z around inf
distribute-rgt-out--N/A
unsub-negN/A
mul-1-negN/A
distribute-lft-inN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -0.165000000000000008 < z < 1.20000000000000003e-4Initial program 98.4%
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.9
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e-79) (not (<= x 2.15e-96))) (fma (* -6.0 x) z x) (* (* 6.0 z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-79) || !(x <= 2.15e-96)) {
tmp = fma((-6.0 * x), z, x);
} else {
tmp = (6.0 * z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e-79) || !(x <= 2.15e-96)) tmp = fma(Float64(-6.0 * x), z, x); else tmp = Float64(Float64(6.0 * z) * y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e-79], N[Not[LessEqual[x, 2.15e-96]], $MachinePrecision]], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-79} \lor \neg \left(x \leq 2.15 \cdot 10^{-96}\right):\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\end{array}
\end{array}
if x < -2.5e-79 or 2.1499999999999999e-96 < x Initial program 98.6%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6485.1
Applied rewrites85.1%
if -2.5e-79 < x < 2.1499999999999999e-96Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6473.3
Applied rewrites73.3%
Applied rewrites73.5%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.4e+24) (fma (* -6.0 z) x x) (if (<= x 4e+46) (fma (* 6.0 y) z x) (* (fma -6.0 z 1.0) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e+24) {
tmp = fma((-6.0 * z), x, x);
} else if (x <= 4e+46) {
tmp = fma((6.0 * y), z, x);
} else {
tmp = fma(-6.0, z, 1.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.4e+24) tmp = fma(Float64(-6.0 * z), x, x); elseif (x <= 4e+46) tmp = fma(Float64(6.0 * y), z, x); else tmp = Float64(fma(-6.0, z, 1.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.4e+24], N[(N[(-6.0 * z), $MachinePrecision] * x + x), $MachinePrecision], If[LessEqual[x, 4e+46], N[(N[(6.0 * y), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(-6.0 * z + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, x, x\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(6 \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.4000000000000001e24Initial program 99.9%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6491.5
Applied rewrites91.5%
Applied rewrites91.5%
if -1.4000000000000001e24 < x < 4e46Initial program 99.7%
Taylor expanded in x around 0
lower-*.f6489.1
Applied rewrites89.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6489.1
Applied rewrites89.1%
if 4e46 < x Initial program 96.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6498.6
Applied rewrites98.6%
Final simplification91.6%
(FPCore (x y z) :precision binary64 (if (<= x -1.4e+24) (fma (* -6.0 z) x x) (if (<= x 4e+46) (fma (* z y) 6.0 x) (* (fma -6.0 z 1.0) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e+24) {
tmp = fma((-6.0 * z), x, x);
} else if (x <= 4e+46) {
tmp = fma((z * y), 6.0, x);
} else {
tmp = fma(-6.0, z, 1.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.4e+24) tmp = fma(Float64(-6.0 * z), x, x); elseif (x <= 4e+46) tmp = fma(Float64(z * y), 6.0, x); else tmp = Float64(fma(-6.0, z, 1.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.4e+24], N[(N[(-6.0 * z), $MachinePrecision] * x + x), $MachinePrecision], If[LessEqual[x, 4e+46], N[(N[(z * y), $MachinePrecision] * 6.0 + x), $MachinePrecision], N[(N[(-6.0 * z + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, x, x\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, 6, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.4000000000000001e24Initial program 99.9%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6491.5
Applied rewrites91.5%
Applied rewrites91.5%
if -1.4000000000000001e24 < x < 4e46Initial program 99.7%
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.7
Applied rewrites99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6489.1
Applied rewrites89.1%
if 4e46 < x Initial program 96.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6498.6
Applied rewrites98.6%
Final simplification91.6%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e-79) (fma (* -6.0 x) z x) (if (<= x 2.15e-96) (* (* 6.0 z) y) (* (fma -6.0 z 1.0) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e-79) {
tmp = fma((-6.0 * x), z, x);
} else if (x <= 2.15e-96) {
tmp = (6.0 * z) * y;
} else {
tmp = fma(-6.0, z, 1.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.5e-79) tmp = fma(Float64(-6.0 * x), z, x); elseif (x <= 2.15e-96) tmp = Float64(Float64(6.0 * z) * y); else tmp = Float64(fma(-6.0, z, 1.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.5e-79], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[x, 2.15e-96], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision], N[(N[(-6.0 * z + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{-96}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -2.5e-79Initial program 99.8%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6484.4
Applied rewrites84.4%
if -2.5e-79 < x < 2.1499999999999999e-96Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6473.3
Applied rewrites73.3%
Applied rewrites73.5%
if 2.1499999999999999e-96 < x Initial program 97.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6488.2
Applied rewrites88.2%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e-79) (fma (* -6.0 x) z x) (if (<= x 2.15e-96) (* (* 6.0 z) y) (fma (* -6.0 z) x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e-79) {
tmp = fma((-6.0 * x), z, x);
} else if (x <= 2.15e-96) {
tmp = (6.0 * z) * y;
} else {
tmp = fma((-6.0 * z), x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.5e-79) tmp = fma(Float64(-6.0 * x), z, x); elseif (x <= 2.15e-96) tmp = Float64(Float64(6.0 * z) * y); else tmp = fma(Float64(-6.0 * z), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.5e-79], N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[x, 2.15e-96], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision], N[(N[(-6.0 * z), $MachinePrecision] * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot x, z, x\right)\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{-96}:\\
\;\;\;\;\left(6 \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6 \cdot z, x, x\right)\\
\end{array}
\end{array}
if x < -2.5e-79Initial program 99.8%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6484.4
Applied rewrites84.4%
if -2.5e-79 < x < 2.1499999999999999e-96Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6473.3
Applied rewrites73.3%
Applied rewrites73.5%
if 2.1499999999999999e-96 < x Initial program 97.4%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6485.8
Applied rewrites85.8%
Applied rewrites88.2%
Final simplification81.5%
(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.0%
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 z) y))
double code(double x, double y, double z) {
return (6.0 * z) * y;
}
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 * z) * y
end function
public static double code(double x, double y, double z) {
return (6.0 * z) * y;
}
def code(x, y, z): return (6.0 * z) * y
function code(x, y, z) return Float64(Float64(6.0 * z) * y) end
function tmp = code(x, y, z) tmp = (6.0 * z) * y; end
code[x_, y_, z_] := N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(6 \cdot z\right) \cdot y
\end{array}
Initial program 99.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6440.2
Applied rewrites40.2%
Applied rewrites40.7%
Final simplification40.7%
(FPCore (x y z) :precision binary64 (* (* 6.0 y) z))
double code(double x, double y, double z) {
return (6.0 * y) * 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 * y) * z
end function
public static double code(double x, double y, double z) {
return (6.0 * y) * z;
}
def code(x, y, z): return (6.0 * y) * z
function code(x, y, z) return Float64(Float64(6.0 * y) * z) end
function tmp = code(x, y, z) tmp = (6.0 * y) * z; end
code[x_, y_, z_] := N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(6 \cdot y\right) \cdot z
\end{array}
Initial program 99.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6440.2
Applied rewrites40.2%
Applied rewrites40.3%
Final simplification40.3%
(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 2024298
(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)))