
(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 6 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 6.0 y (* x -6.0)) z)))
double code(double x, double y, double z) {
return x + (fma(6.0, y, (x * -6.0)) * z);
}
function code(x, y, z) return Float64(x + Float64(fma(6.0, y, Float64(x * -6.0)) * z)) end
code[x_, y_, z_] := N[(x + N[(N[(6.0 * y + N[(x * -6.0), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(6, y, x \cdot -6\right) \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.2e-39) (not (<= x 2e+120))) (+ x (* -6.0 (* x z))) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e-39) || !(x <= 2e+120)) {
tmp = x + (-6.0 * (x * z));
} 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 <= (-2.2d-39)) .or. (.not. (x <= 2d+120))) then
tmp = x + ((-6.0d0) * (x * z))
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 <= -2.2e-39) || !(x <= 2e+120)) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.2e-39) or not (x <= 2e+120): tmp = x + (-6.0 * (x * z)) else: tmp = x + (6.0 * (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.2e-39) || !(x <= 2e+120)) tmp = Float64(x + Float64(-6.0 * Float64(x * z))); 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 <= -2.2e-39) || ~((x <= 2e+120))) tmp = x + (-6.0 * (x * z)); else tmp = x + (6.0 * (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.2e-39], N[Not[LessEqual[x, 2e+120]], $MachinePrecision]], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{-39} \lor \neg \left(x \leq 2 \cdot 10^{+120}\right):\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < -2.20000000000000001e-39 or 2e120 < x Initial program 99.9%
Taylor expanded in y around 0 92.6%
if -2.20000000000000001e-39 < x < 2e120Initial program 99.8%
Taylor expanded in y around inf 92.4%
*-commutative92.4%
Simplified92.4%
Final simplification92.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.65e-43) (not (<= x 2e+120))) (+ x (* -6.0 (* x z))) (+ x (* y (* 6.0 z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.65e-43) || !(x <= 2e+120)) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = x + (y * (6.0 * 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 <= (-2.65d-43)) .or. (.not. (x <= 2d+120))) then
tmp = x + ((-6.0d0) * (x * z))
else
tmp = x + (y * (6.0d0 * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.65e-43) || !(x <= 2e+120)) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = x + (y * (6.0 * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.65e-43) or not (x <= 2e+120): tmp = x + (-6.0 * (x * z)) else: tmp = x + (y * (6.0 * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.65e-43) || !(x <= 2e+120)) tmp = Float64(x + Float64(-6.0 * Float64(x * z))); else tmp = Float64(x + Float64(y * Float64(6.0 * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.65e-43) || ~((x <= 2e+120))) tmp = x + (-6.0 * (x * z)); else tmp = x + (y * (6.0 * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.65e-43], N[Not[LessEqual[x, 2e+120]], $MachinePrecision]], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{-43} \lor \neg \left(x \leq 2 \cdot 10^{+120}\right):\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(6 \cdot z\right)\\
\end{array}
\end{array}
if x < -2.6500000000000002e-43 or 2e120 < x Initial program 99.9%
Taylor expanded in y around 0 92.6%
if -2.6500000000000002e-43 < x < 2e120Initial program 99.8%
Taylor expanded in y around 0 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 92.4%
associate-*r*92.5%
*-commutative92.5%
associate-*l*92.5%
Simplified92.5%
Final simplification92.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e-39) (not (<= x 6.2e+120))) (+ x (* (* x -6.0) z)) (+ x (* y (* 6.0 z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-39) || !(x <= 6.2e+120)) {
tmp = x + ((x * -6.0) * z);
} else {
tmp = x + (y * (6.0 * 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 <= (-1.65d-39)) .or. (.not. (x <= 6.2d+120))) then
tmp = x + ((x * (-6.0d0)) * z)
else
tmp = x + (y * (6.0d0 * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-39) || !(x <= 6.2e+120)) {
tmp = x + ((x * -6.0) * z);
} else {
tmp = x + (y * (6.0 * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e-39) or not (x <= 6.2e+120): tmp = x + ((x * -6.0) * z) else: tmp = x + (y * (6.0 * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.65e-39) || !(x <= 6.2e+120)) tmp = Float64(x + Float64(Float64(x * -6.0) * z)); else tmp = Float64(x + Float64(y * Float64(6.0 * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.65e-39) || ~((x <= 6.2e+120))) tmp = x + ((x * -6.0) * z); else tmp = x + (y * (6.0 * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e-39], N[Not[LessEqual[x, 6.2e+120]], $MachinePrecision]], N[(x + N[(N[(x * -6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-39} \lor \neg \left(x \leq 6.2 \cdot 10^{+120}\right):\\
\;\;\;\;x + \left(x \cdot -6\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(6 \cdot z\right)\\
\end{array}
\end{array}
if x < -1.64999999999999992e-39 or 6.19999999999999947e120 < x Initial program 99.9%
Taylor expanded in y around 0 92.6%
associate-*r*92.6%
Simplified92.6%
if -1.64999999999999992e-39 < x < 6.19999999999999947e120Initial program 99.8%
Taylor expanded in y around 0 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 92.4%
associate-*r*92.5%
*-commutative92.5%
associate-*l*92.5%
Simplified92.5%
Final simplification92.5%
(FPCore (x y z) :precision binary64 (- x (* z (* 6.0 (- x y)))))
double code(double x, double y, double z) {
return x - (z * (6.0 * (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 - (z * (6.0d0 * (x - y)))
end function
public static double code(double x, double y, double z) {
return x - (z * (6.0 * (x - y)));
}
def code(x, y, z): return x - (z * (6.0 * (x - y)))
function code(x, y, z) return Float64(x - Float64(z * Float64(6.0 * Float64(x - y)))) end
function tmp = code(x, y, z) tmp = x - (z * (6.0 * (x - y))); end
code[x_, y_, z_] := N[(x - N[(z * N[(6.0 * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot \left(6 \cdot \left(x - y\right)\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ x (* -6.0 (* x z))))
double code(double x, double y, double z) {
return x + (-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 = x + ((-6.0d0) * (x * z))
end function
public static double code(double x, double y, double z) {
return x + (-6.0 * (x * z));
}
def code(x, y, z): return x + (-6.0 * (x * z))
function code(x, y, z) return Float64(x + Float64(-6.0 * Float64(x * z))) end
function tmp = code(x, y, z) tmp = x + (-6.0 * (x * z)); end
code[x_, y_, z_] := N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + -6 \cdot \left(x \cdot z\right)
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 62.9%
Final simplification62.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 2024034
(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)))