
(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 7 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 (+ x (* 6.0 (* z (- y x)))))
double code(double x, double y, double z) {
return x + (6.0 * (z * (y - x)));
}
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 * (y - x)))
end function
public static double code(double x, double y, double z) {
return x + (6.0 * (z * (y - x)));
}
def code(x, y, z): return x + (6.0 * (z * (y - x)))
function code(x, y, z) return Float64(x + Float64(6.0 * Float64(z * Float64(y - x)))) end
function tmp = code(x, y, z) tmp = x + (6.0 * (z * (y - x))); end
code[x_, y_, z_] := N[(x + N[(6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + 6 \cdot \left(z \cdot \left(y - x\right)\right)
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 98.2%
+-commutative98.2%
*-commutative98.2%
associate-*l*98.2%
*-commutative98.2%
metadata-eval98.2%
cancel-sign-sub-inv98.2%
associate-*l*98.2%
*-commutative98.2%
distribute-lft-out--99.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e+37) (not (<= y 2.95e-134))) (+ x (* 6.0 (* z y))) (* x (+ 1.0 (* z -6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+37) || !(y <= 2.95e-134)) {
tmp = x + (6.0 * (z * y));
} else {
tmp = x * (1.0 + (z * -6.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) :: tmp
if ((y <= (-4d+37)) .or. (.not. (y <= 2.95d-134))) then
tmp = x + (6.0d0 * (z * y))
else
tmp = x * (1.0d0 + (z * (-6.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+37) || !(y <= 2.95e-134)) {
tmp = x + (6.0 * (z * y));
} else {
tmp = x * (1.0 + (z * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e+37) or not (y <= 2.95e-134): tmp = x + (6.0 * (z * y)) else: tmp = x * (1.0 + (z * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e+37) || !(y <= 2.95e-134)) tmp = Float64(x + Float64(6.0 * Float64(z * y))); else tmp = Float64(x * Float64(1.0 + Float64(z * -6.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4e+37) || ~((y <= 2.95e-134))) tmp = x + (6.0 * (z * y)); else tmp = x * (1.0 + (z * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e+37], N[Not[LessEqual[y, 2.95e-134]], $MachinePrecision]], N[(x + N[(6.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+37} \lor \neg \left(y \leq 2.95 \cdot 10^{-134}\right):\\
\;\;\;\;x + 6 \cdot \left(z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + z \cdot -6\right)\\
\end{array}
\end{array}
if y < -3.99999999999999982e37 or 2.95e-134 < y Initial program 99.7%
Taylor expanded in y around inf 92.4%
if -3.99999999999999982e37 < y < 2.95e-134Initial program 99.8%
Taylor expanded in y around 0 87.0%
Taylor expanded in x around 0 87.0%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.95e+38) (+ x (* z (* 6.0 y))) (if (<= y 2.65e-133) (* x (+ 1.0 (* z -6.0))) (+ x (* 6.0 (* z y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.95e+38) {
tmp = x + (z * (6.0 * y));
} else if (y <= 2.65e-133) {
tmp = x * (1.0 + (z * -6.0));
} else {
tmp = x + (6.0 * (z * y));
}
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 (y <= (-2.95d+38)) then
tmp = x + (z * (6.0d0 * y))
else if (y <= 2.65d-133) then
tmp = x * (1.0d0 + (z * (-6.0d0)))
else
tmp = x + (6.0d0 * (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.95e+38) {
tmp = x + (z * (6.0 * y));
} else if (y <= 2.65e-133) {
tmp = x * (1.0 + (z * -6.0));
} else {
tmp = x + (6.0 * (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.95e+38: tmp = x + (z * (6.0 * y)) elif y <= 2.65e-133: tmp = x * (1.0 + (z * -6.0)) else: tmp = x + (6.0 * (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.95e+38) tmp = Float64(x + Float64(z * Float64(6.0 * y))); elseif (y <= 2.65e-133) tmp = Float64(x * Float64(1.0 + Float64(z * -6.0))); else tmp = Float64(x + Float64(6.0 * Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.95e+38) tmp = x + (z * (6.0 * y)); elseif (y <= 2.65e-133) tmp = x * (1.0 + (z * -6.0)); else tmp = x + (6.0 * (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.95e+38], N[(x + N[(z * N[(6.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.65e-133], N[(x * N[(1.0 + N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.95 \cdot 10^{+38}:\\
\;\;\;\;x + z \cdot \left(6 \cdot y\right)\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-133}:\\
\;\;\;\;x \cdot \left(1 + z \cdot -6\right)\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if y < -2.94999999999999991e38Initial program 99.8%
Taylor expanded in y around inf 94.1%
if -2.94999999999999991e38 < y < 2.64999999999999992e-133Initial program 99.8%
Taylor expanded in y around 0 87.0%
Taylor expanded in x around 0 87.0%
if 2.64999999999999992e-133 < y Initial program 99.7%
Taylor expanded in y around inf 91.4%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.17) (not (<= z 1.36e-8))) (* -6.0 (* x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.17) || !(z <= 1.36e-8)) {
tmp = -6.0 * (x * z);
} else {
tmp = 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 ((z <= (-0.17d0)) .or. (.not. (z <= 1.36d-8))) then
tmp = (-6.0d0) * (x * z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -0.17) || !(z <= 1.36e-8)) {
tmp = -6.0 * (x * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.17) or not (z <= 1.36e-8): tmp = -6.0 * (x * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.17) || !(z <= 1.36e-8)) tmp = Float64(-6.0 * Float64(x * z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.17) || ~((z <= 1.36e-8))) tmp = -6.0 * (x * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.17], N[Not[LessEqual[z, 1.36e-8]], $MachinePrecision]], N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 1.36 \cdot 10^{-8}\right):\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.170000000000000012 or 1.3599999999999999e-8 < z Initial program 99.6%
Taylor expanded in y around 0 45.2%
Taylor expanded in x around 0 45.3%
Taylor expanded in z around inf 43.5%
if -0.170000000000000012 < z < 1.3599999999999999e-8Initial program 99.9%
Taylor expanded in y around 0 77.5%
Taylor expanded in z around 0 76.9%
Final simplification60.2%
(FPCore (x y z) :precision binary64 (if (<= z -0.17) (* -6.0 (* x z)) (if (<= z 1.36e-8) x (* x (* z -6.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.17) {
tmp = -6.0 * (x * z);
} else if (z <= 1.36e-8) {
tmp = x;
} else {
tmp = x * (z * -6.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) :: tmp
if (z <= (-0.17d0)) then
tmp = (-6.0d0) * (x * z)
else if (z <= 1.36d-8) then
tmp = x
else
tmp = x * (z * (-6.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.17) {
tmp = -6.0 * (x * z);
} else if (z <= 1.36e-8) {
tmp = x;
} else {
tmp = x * (z * -6.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.17: tmp = -6.0 * (x * z) elif z <= 1.36e-8: tmp = x else: tmp = x * (z * -6.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.17) tmp = Float64(-6.0 * Float64(x * z)); elseif (z <= 1.36e-8) tmp = x; else tmp = Float64(x * Float64(z * -6.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.17) tmp = -6.0 * (x * z); elseif (z <= 1.36e-8) tmp = x; else tmp = x * (z * -6.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.17], N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.36e-8], x, N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17:\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\mathbf{elif}\;z \leq 1.36 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z \cdot -6\right)\\
\end{array}
\end{array}
if z < -0.170000000000000012Initial program 99.6%
Taylor expanded in y around 0 46.4%
Taylor expanded in x around 0 46.4%
Taylor expanded in z around inf 43.3%
if -0.170000000000000012 < z < 1.3599999999999999e-8Initial program 99.9%
Taylor expanded in y around 0 77.5%
Taylor expanded in z around 0 76.9%
if 1.3599999999999999e-8 < z Initial program 99.5%
Taylor expanded in y around 0 43.8%
Taylor expanded in x around 0 43.9%
Taylor expanded in z around inf 43.6%
associate-*r*43.7%
Simplified43.7%
Final simplification60.2%
(FPCore (x y z) :precision binary64 (* x (+ 1.0 (* z -6.0))))
double code(double x, double y, double z) {
return x * (1.0 + (z * -6.0));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 + (z * (-6.0d0)))
end function
public static double code(double x, double y, double z) {
return x * (1.0 + (z * -6.0));
}
def code(x, y, z): return x * (1.0 + (z * -6.0))
function code(x, y, z) return Float64(x * Float64(1.0 + Float64(z * -6.0))) end
function tmp = code(x, y, z) tmp = x * (1.0 + (z * -6.0)); end
code[x_, y_, z_] := N[(x * N[(1.0 + N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + z \cdot -6\right)
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 61.4%
Taylor expanded in x around 0 61.4%
Final simplification61.4%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 61.4%
Taylor expanded in z around 0 40.1%
Final simplification40.1%
(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 2023257
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:herbie-target
(- x (* (* 6.0 z) (- x y)))
(+ x (* (* (- y x) 6.0) z)))