
(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 9 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(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%
fma-udef99.8%
*-commutative99.8%
distribute-lft-neg-out99.8%
unsub-neg99.8%
*-commutative99.8%
*-commutative99.8%
Applied egg-rr99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e+83) (not (<= x 4.5e+59))) (+ x (* -6.0 (* x z))) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+83) || !(x <= 4.5e+59)) {
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 <= (-3.7d+83)) .or. (.not. (x <= 4.5d+59))) 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 <= -3.7e+83) || !(x <= 4.5e+59)) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e+83) or not (x <= 4.5e+59): 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 <= -3.7e+83) || !(x <= 4.5e+59)) 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 <= -3.7e+83) || ~((x <= 4.5e+59))) 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, -3.7e+83], N[Not[LessEqual[x, 4.5e+59]], $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 -3.7 \cdot 10^{+83} \lor \neg \left(x \leq 4.5 \cdot 10^{+59}\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 < -3.7000000000000002e83 or 4.49999999999999959e59 < x Initial program 99.9%
Taylor expanded in y around 0 94.9%
if -3.7000000000000002e83 < x < 4.49999999999999959e59Initial program 99.8%
Taylor expanded in y around inf 87.8%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e+79) (not (<= x 5.5e+68))) (+ x (* (* x -6.0) z)) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e+79) || !(x <= 5.5e+68)) {
tmp = x + ((x * -6.0) * 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 <= (-3d+79)) .or. (.not. (x <= 5.5d+68))) then
tmp = x + ((x * (-6.0d0)) * 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 <= -3e+79) || !(x <= 5.5e+68)) {
tmp = x + ((x * -6.0) * z);
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e+79) or not (x <= 5.5e+68): tmp = x + ((x * -6.0) * z) else: tmp = x + (6.0 * (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e+79) || !(x <= 5.5e+68)) tmp = Float64(x + Float64(Float64(x * -6.0) * 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 <= -3e+79) || ~((x <= 5.5e+68))) tmp = x + ((x * -6.0) * z); else tmp = x + (6.0 * (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e+79], N[Not[LessEqual[x, 5.5e+68]], $MachinePrecision]], N[(x + N[(N[(x * -6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+79} \lor \neg \left(x \leq 5.5 \cdot 10^{+68}\right):\\
\;\;\;\;x + \left(x \cdot -6\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < -2.99999999999999974e79 or 5.5000000000000004e68 < x Initial program 99.9%
Taylor expanded in y around 0 94.9%
if -2.99999999999999974e79 < x < 5.5000000000000004e68Initial program 99.8%
Taylor expanded in y around inf 87.8%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e+80) (not (<= x 2.7e+63))) (+ x (* (* x -6.0) z)) (+ x (* z (* y 6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e+80) || !(x <= 2.7e+63)) {
tmp = x + ((x * -6.0) * z);
} else {
tmp = x + (z * (y * 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 <= (-6.8d+80)) .or. (.not. (x <= 2.7d+63))) then
tmp = x + ((x * (-6.0d0)) * z)
else
tmp = x + (z * (y * 6.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e+80) || !(x <= 2.7e+63)) {
tmp = x + ((x * -6.0) * z);
} else {
tmp = x + (z * (y * 6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e+80) or not (x <= 2.7e+63): tmp = x + ((x * -6.0) * z) else: tmp = x + (z * (y * 6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e+80) || !(x <= 2.7e+63)) tmp = Float64(x + Float64(Float64(x * -6.0) * z)); else tmp = Float64(x + Float64(z * Float64(y * 6.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.8e+80) || ~((x <= 2.7e+63))) tmp = x + ((x * -6.0) * z); else tmp = x + (z * (y * 6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e+80], N[Not[LessEqual[x, 2.7e+63]], $MachinePrecision]], N[(x + N[(N[(x * -6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+80} \lor \neg \left(x \leq 2.7 \cdot 10^{+63}\right):\\
\;\;\;\;x + \left(x \cdot -6\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(y \cdot 6\right)\\
\end{array}
\end{array}
if x < -6.79999999999999984e80 or 2.70000000000000017e63 < x Initial program 99.9%
Taylor expanded in y around 0 94.9%
if -6.79999999999999984e80 < x < 2.70000000000000017e63Initial program 99.8%
Taylor expanded in y around inf 87.8%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -21000000.0) (not (<= z 0.17))) (* -6.0 (* x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -21000000.0) || !(z <= 0.17)) {
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 <= (-21000000.0d0)) .or. (.not. (z <= 0.17d0))) 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 <= -21000000.0) || !(z <= 0.17)) {
tmp = -6.0 * (x * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -21000000.0) or not (z <= 0.17): tmp = -6.0 * (x * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -21000000.0) || !(z <= 0.17)) 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 <= -21000000.0) || ~((z <= 0.17))) tmp = -6.0 * (x * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -21000000.0], N[Not[LessEqual[z, 0.17]], $MachinePrecision]], N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -21000000 \lor \neg \left(z \leq 0.17\right):\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1e7 or 0.170000000000000012 < z Initial program 99.8%
Taylor expanded in y around 0 52.1%
Taylor expanded in z around inf 52.1%
if -2.1e7 < z < 0.170000000000000012Initial program 99.9%
Taylor expanded in z around 0 66.0%
Final simplification59.6%
(FPCore (x y z) :precision binary64 (if (<= z -21000000.0) (* x (* -6.0 z)) (if (<= z 0.17) x (* -6.0 (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -21000000.0) {
tmp = x * (-6.0 * z);
} else if (z <= 0.17) {
tmp = x;
} else {
tmp = -6.0 * (x * 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 (z <= (-21000000.0d0)) then
tmp = x * ((-6.0d0) * z)
else if (z <= 0.17d0) then
tmp = x
else
tmp = (-6.0d0) * (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -21000000.0) {
tmp = x * (-6.0 * z);
} else if (z <= 0.17) {
tmp = x;
} else {
tmp = -6.0 * (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -21000000.0: tmp = x * (-6.0 * z) elif z <= 0.17: tmp = x else: tmp = -6.0 * (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -21000000.0) tmp = Float64(x * Float64(-6.0 * z)); elseif (z <= 0.17) tmp = x; else tmp = Float64(-6.0 * Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -21000000.0) tmp = x * (-6.0 * z); elseif (z <= 0.17) tmp = x; else tmp = -6.0 * (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -21000000.0], N[(x * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.17], x, N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -21000000:\\
\;\;\;\;x \cdot \left(-6 \cdot z\right)\\
\mathbf{elif}\;z \leq 0.17:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if z < -2.1e7Initial program 99.8%
Taylor expanded in y around 0 57.3%
Taylor expanded in z around inf 57.3%
associate-*r*57.4%
*-commutative57.4%
associate-*r*57.4%
Simplified57.4%
if -2.1e7 < z < 0.170000000000000012Initial program 99.9%
Taylor expanded in z around 0 66.0%
if 0.170000000000000012 < z Initial program 99.8%
Taylor expanded in y around 0 46.2%
Taylor expanded in z around inf 46.2%
Final simplification59.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 (* 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.8%
Taylor expanded in y around 0 60.6%
Final simplification60.6%
(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 37.0%
Final simplification37.0%
(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 2024041
(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)))