
(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 (* (fma y 6.0 (- (* x 6.0))) z)))
double code(double x, double y, double z) {
return x + (fma(y, 6.0, -(x * 6.0)) * z);
}
function code(x, y, z) return Float64(x + Float64(fma(y, 6.0, Float64(-Float64(x * 6.0))) * z)) end
code[x_, y_, z_] := N[(x + N[(N[(y * 6.0 + (-N[(x * 6.0), $MachinePrecision])), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(y, 6, -x \cdot 6\right) \cdot z
\end{array}
Initial program 99.8%
*-commutative99.8%
sub-neg99.8%
distribute-rgt-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.4e+44) (not (<= x 6.6e+44))) (+ x (* x (* z -6.0))) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e+44) || !(x <= 6.6e+44)) {
tmp = x + (x * (z * -6.0));
} else {
tmp = x + (6.0 * (y * z));
}
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 <= (-3.4d+44)) .or. (.not. (x <= 6.6d+44))) then
tmp = x + (x * (z * (-6.0d0)))
else
tmp = x + (6.0d0 * (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e+44) || !(x <= 6.6e+44)) {
tmp = x + (x * (z * -6.0));
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e+44) or not (x <= 6.6e+44): tmp = x + (x * (z * -6.0)) else: tmp = x + (6.0 * (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e+44) || !(x <= 6.6e+44)) tmp = Float64(x + Float64(x * Float64(z * -6.0))); else tmp = Float64(x + Float64(6.0 * Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.4e+44) || ~((x <= 6.6e+44))) tmp = x + (x * (z * -6.0)); else tmp = x + (6.0 * (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e+44], N[Not[LessEqual[x, 6.6e+44]], $MachinePrecision]], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+44} \lor \neg \left(x \leq 6.6 \cdot 10^{+44}\right):\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < -3.4e44 or 6.60000000000000027e44 < x Initial program 99.9%
Taylor expanded in y around 0 91.2%
*-commutative91.2%
associate-*r*91.2%
*-commutative91.2%
Simplified91.2%
if -3.4e44 < x < 6.60000000000000027e44Initial program 99.8%
Taylor expanded in y around inf 88.1%
*-commutative88.1%
Simplified88.1%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= x -4e+44) (+ x (* x (* z -6.0))) (if (<= x 6.2e+44) (+ x (* 6.0 (* y z))) (+ x (* z (* x -6.0))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4e+44) {
tmp = x + (x * (z * -6.0));
} else if (x <= 6.2e+44) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (z * (x * -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 (x <= (-4d+44)) then
tmp = x + (x * (z * (-6.0d0)))
else if (x <= 6.2d+44) then
tmp = x + (6.0d0 * (y * z))
else
tmp = x + (z * (x * (-6.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4e+44) {
tmp = x + (x * (z * -6.0));
} else if (x <= 6.2e+44) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (z * (x * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4e+44: tmp = x + (x * (z * -6.0)) elif x <= 6.2e+44: tmp = x + (6.0 * (y * z)) else: tmp = x + (z * (x * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4e+44) tmp = Float64(x + Float64(x * Float64(z * -6.0))); elseif (x <= 6.2e+44) tmp = Float64(x + Float64(6.0 * Float64(y * z))); else tmp = Float64(x + Float64(z * Float64(x * -6.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4e+44) tmp = x + (x * (z * -6.0)); elseif (x <= 6.2e+44) tmp = x + (6.0 * (y * z)); else tmp = x + (z * (x * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4e+44], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.2e+44], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(x * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+44}:\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{+44}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(x \cdot -6\right)\\
\end{array}
\end{array}
if x < -4.0000000000000004e44Initial program 99.9%
Taylor expanded in y around 0 89.1%
*-commutative89.1%
associate-*r*89.1%
*-commutative89.1%
Simplified89.1%
if -4.0000000000000004e44 < x < 6.19999999999999991e44Initial program 99.8%
Taylor expanded in y around inf 88.1%
*-commutative88.1%
Simplified88.1%
if 6.19999999999999991e44 < x Initial program 100.0%
Taylor expanded in y around 0 93.3%
associate-*r*93.3%
Simplified93.3%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= x -5.2e+44) (+ x (* x (* z -6.0))) (if (<= x 3.45e+44) (+ x (* z (* y 6.0))) (+ x (* z (* x -6.0))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+44) {
tmp = x + (x * (z * -6.0));
} else if (x <= 3.45e+44) {
tmp = x + (z * (y * 6.0));
} else {
tmp = x + (z * (x * -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 (x <= (-5.2d+44)) then
tmp = x + (x * (z * (-6.0d0)))
else if (x <= 3.45d+44) then
tmp = x + (z * (y * 6.0d0))
else
tmp = x + (z * (x * (-6.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+44) {
tmp = x + (x * (z * -6.0));
} else if (x <= 3.45e+44) {
tmp = x + (z * (y * 6.0));
} else {
tmp = x + (z * (x * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.2e+44: tmp = x + (x * (z * -6.0)) elif x <= 3.45e+44: tmp = x + (z * (y * 6.0)) else: tmp = x + (z * (x * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.2e+44) tmp = Float64(x + Float64(x * Float64(z * -6.0))); elseif (x <= 3.45e+44) tmp = Float64(x + Float64(z * Float64(y * 6.0))); else tmp = Float64(x + Float64(z * Float64(x * -6.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.2e+44) tmp = x + (x * (z * -6.0)); elseif (x <= 3.45e+44) tmp = x + (z * (y * 6.0)); else tmp = x + (z * (x * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.2e+44], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.45e+44], N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(x * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+44}:\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;x \leq 3.45 \cdot 10^{+44}:\\
\;\;\;\;x + z \cdot \left(y \cdot 6\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(x \cdot -6\right)\\
\end{array}
\end{array}
if x < -5.1999999999999998e44Initial program 99.9%
Taylor expanded in y around 0 89.1%
*-commutative89.1%
associate-*r*89.1%
*-commutative89.1%
Simplified89.1%
if -5.1999999999999998e44 < x < 3.4499999999999999e44Initial program 99.8%
Taylor expanded in y around inf 88.1%
if 3.4499999999999999e44 < x Initial program 100.0%
Taylor expanded in y around 0 93.3%
associate-*r*93.3%
Simplified93.3%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (+ x (* z (* 6.0 (- y x)))))
double code(double x, double y, double z) {
return x + (z * (6.0 * (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 + (z * (6.0d0 * (y - x)))
end function
public static double code(double x, double y, double z) {
return x + (z * (6.0 * (y - x)));
}
def code(x, y, z): return x + (z * (6.0 * (y - x)))
function code(x, y, z) return Float64(x + Float64(z * Float64(6.0 * Float64(y - x)))) end
function tmp = code(x, y, z) tmp = x + (z * (6.0 * (y - x))); end
code[x_, y_, z_] := N[(x + N[(z * N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \left(6 \cdot \left(y - x\right)\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ x (* 6.0 (* y z))))
double code(double x, double y, double z) {
return x + (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 = x + (6.0d0 * (y * z))
end function
public static double code(double x, double y, double z) {
return x + (6.0 * (y * z));
}
def code(x, y, z): return x + (6.0 * (y * z))
function code(x, y, z) return Float64(x + Float64(6.0 * Float64(y * z))) end
function tmp = code(x, y, z) tmp = x + (6.0 * (y * z)); end
code[x_, y_, z_] := N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + 6 \cdot \left(y \cdot z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around inf 77.1%
*-commutative77.1%
Simplified77.1%
Final simplification77.1%
(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.8%
Taylor expanded in z around 0 35.7%
Final simplification35.7%
(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 2023310
(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)))