
(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 (* 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.4%
Taylor expanded in z around 0 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 6.0 (* z y))) (t_1 (* -6.0 (* z x))))
(if (<= y -4e-62)
t_0
(if (<= y 1.25e-85)
t_1
(if (<= y 5.8e-49)
t_0
(if (<= y 3.7e-33) t_1 (if (<= y 3e+87) x t_0)))))))
double code(double x, double y, double z) {
double t_0 = 6.0 * (z * y);
double t_1 = -6.0 * (z * x);
double tmp;
if (y <= -4e-62) {
tmp = t_0;
} else if (y <= 1.25e-85) {
tmp = t_1;
} else if (y <= 5.8e-49) {
tmp = t_0;
} else if (y <= 3.7e-33) {
tmp = t_1;
} else if (y <= 3e+87) {
tmp = x;
} else {
tmp = t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 6.0d0 * (z * y)
t_1 = (-6.0d0) * (z * x)
if (y <= (-4d-62)) then
tmp = t_0
else if (y <= 1.25d-85) then
tmp = t_1
else if (y <= 5.8d-49) then
tmp = t_0
else if (y <= 3.7d-33) then
tmp = t_1
else if (y <= 3d+87) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 6.0 * (z * y);
double t_1 = -6.0 * (z * x);
double tmp;
if (y <= -4e-62) {
tmp = t_0;
} else if (y <= 1.25e-85) {
tmp = t_1;
} else if (y <= 5.8e-49) {
tmp = t_0;
} else if (y <= 3.7e-33) {
tmp = t_1;
} else if (y <= 3e+87) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 6.0 * (z * y) t_1 = -6.0 * (z * x) tmp = 0 if y <= -4e-62: tmp = t_0 elif y <= 1.25e-85: tmp = t_1 elif y <= 5.8e-49: tmp = t_0 elif y <= 3.7e-33: tmp = t_1 elif y <= 3e+87: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(6.0 * Float64(z * y)) t_1 = Float64(-6.0 * Float64(z * x)) tmp = 0.0 if (y <= -4e-62) tmp = t_0; elseif (y <= 1.25e-85) tmp = t_1; elseif (y <= 5.8e-49) tmp = t_0; elseif (y <= 3.7e-33) tmp = t_1; elseif (y <= 3e+87) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 6.0 * (z * y); t_1 = -6.0 * (z * x); tmp = 0.0; if (y <= -4e-62) tmp = t_0; elseif (y <= 1.25e-85) tmp = t_1; elseif (y <= 5.8e-49) tmp = t_0; elseif (y <= 3.7e-33) tmp = t_1; elseif (y <= 3e+87) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(6.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-6.0 * N[(z * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4e-62], t$95$0, If[LessEqual[y, 1.25e-85], t$95$1, If[LessEqual[y, 5.8e-49], t$95$0, If[LessEqual[y, 3.7e-33], t$95$1, If[LessEqual[y, 3e+87], x, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 6 \cdot \left(z \cdot y\right)\\
t_1 := -6 \cdot \left(z \cdot x\right)\\
\mathbf{if}\;y \leq -4 \cdot 10^{-62}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-85}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-49}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-33}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+87}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.0000000000000002e-62 or 1.25e-85 < y < 5.8e-49 or 2.9999999999999999e87 < y Initial program 99.7%
Taylor expanded in z around 0 99.8%
Taylor expanded in z around inf 84.8%
Taylor expanded in y around inf 78.6%
if -4.0000000000000002e-62 < y < 1.25e-85 or 5.8e-49 < y < 3.70000000000000014e-33Initial program 98.9%
Taylor expanded in z around 0 99.8%
Taylor expanded in z around inf 66.8%
Taylor expanded in y around 0 58.5%
if 3.70000000000000014e-33 < y < 2.9999999999999999e87Initial program 99.7%
Taylor expanded in z around 0 42.3%
Final simplification66.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.4e-80) (not (<= z 2.45e-27))) (* 6.0 (* z (- y x))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e-80) || !(z <= 2.45e-27)) {
tmp = 6.0 * (z * (y - x));
} 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 <= (-3.4d-80)) .or. (.not. (z <= 2.45d-27))) then
tmp = 6.0d0 * (z * (y - x))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e-80) || !(z <= 2.45e-27)) {
tmp = 6.0 * (z * (y - x));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.4e-80) or not (z <= 2.45e-27): tmp = 6.0 * (z * (y - x)) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.4e-80) || !(z <= 2.45e-27)) tmp = Float64(6.0 * Float64(z * Float64(y - x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.4e-80) || ~((z <= 2.45e-27))) tmp = 6.0 * (z * (y - x)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.4e-80], N[Not[LessEqual[z, 2.45e-27]], $MachinePrecision]], N[(6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-80} \lor \neg \left(z \leq 2.45 \cdot 10^{-27}\right):\\
\;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.4000000000000001e-80 or 2.44999999999999988e-27 < z Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in z around inf 97.5%
if -3.4000000000000001e-80 < z < 2.44999999999999988e-27Initial program 98.7%
Taylor expanded in z around 0 67.3%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.2e-81) (not (<= z 3.85e-28))) (* 6.0 (* z (- y x))) (* x (+ 1.0 (* z -6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.2e-81) || !(z <= 3.85e-28)) {
tmp = 6.0 * (z * (y - x));
} 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 ((z <= (-8.2d-81)) .or. (.not. (z <= 3.85d-28))) then
tmp = 6.0d0 * (z * (y - x))
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 ((z <= -8.2e-81) || !(z <= 3.85e-28)) {
tmp = 6.0 * (z * (y - x));
} else {
tmp = x * (1.0 + (z * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.2e-81) or not (z <= 3.85e-28): tmp = 6.0 * (z * (y - x)) else: tmp = x * (1.0 + (z * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.2e-81) || !(z <= 3.85e-28)) tmp = Float64(6.0 * Float64(z * Float64(y - x))); 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 ((z <= -8.2e-81) || ~((z <= 3.85e-28))) tmp = 6.0 * (z * (y - x)); else tmp = x * (1.0 + (z * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.2e-81], N[Not[LessEqual[z, 3.85e-28]], $MachinePrecision]], N[(6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{-81} \lor \neg \left(z \leq 3.85 \cdot 10^{-28}\right):\\
\;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + z \cdot -6\right)\\
\end{array}
\end{array}
if z < -8.19999999999999968e-81 or 3.85e-28 < z Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in z around inf 97.5%
if -8.19999999999999968e-81 < z < 3.85e-28Initial program 98.7%
Taylor expanded in x around inf 67.3%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.17) (not (<= z 1.2e-26))) (* 6.0 (* z (- y x))) (+ x (* 6.0 (* z y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.17) || !(z <= 1.2e-26)) {
tmp = 6.0 * (z * (y - x));
} 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 ((z <= (-0.17d0)) .or. (.not. (z <= 1.2d-26))) then
tmp = 6.0d0 * (z * (y - x))
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 ((z <= -0.17) || !(z <= 1.2e-26)) {
tmp = 6.0 * (z * (y - x));
} else {
tmp = x + (6.0 * (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.17) or not (z <= 1.2e-26): tmp = 6.0 * (z * (y - x)) else: tmp = x + (6.0 * (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.17) || !(z <= 1.2e-26)) tmp = Float64(6.0 * Float64(z * Float64(y - x))); 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 ((z <= -0.17) || ~((z <= 1.2e-26))) tmp = 6.0 * (z * (y - x)); else tmp = x + (6.0 * (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.17], N[Not[LessEqual[z, 1.2e-26]], $MachinePrecision]], N[(6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 1.2 \cdot 10^{-26}\right):\\
\;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if z < -0.170000000000000012 or 1.2e-26 < z Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in z around inf 99.1%
if -0.170000000000000012 < z < 1.2e-26Initial program 98.8%
Taylor expanded in y around inf 98.8%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.17) (not (<= z 0.37))) (* -6.0 (* z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.17) || !(z <= 0.37)) {
tmp = -6.0 * (z * x);
} 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 <= 0.37d0))) then
tmp = (-6.0d0) * (z * x)
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 <= 0.37)) {
tmp = -6.0 * (z * x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.17) or not (z <= 0.37): tmp = -6.0 * (z * x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.17) || !(z <= 0.37)) tmp = Float64(-6.0 * Float64(z * x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.17) || ~((z <= 0.37))) tmp = -6.0 * (z * x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.17], N[Not[LessEqual[z, 0.37]], $MachinePrecision]], N[(-6.0 * N[(z * x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 0.37\right):\\
\;\;\;\;-6 \cdot \left(z \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.170000000000000012 or 0.37 < z Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in z around inf 99.0%
Taylor expanded in y around 0 56.3%
if -0.170000000000000012 < z < 0.37Initial program 98.8%
Taylor expanded in z around 0 60.4%
Final simplification58.0%
(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.4%
Final simplification99.4%
(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(y - x) * Float64(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[(y - x), $MachinePrecision] * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot \left(6 \cdot z\right)
\end{array}
Initial program 99.4%
associate-*l*99.7%
Simplified99.7%
Final simplification99.7%
(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.4%
Taylor expanded in z around 0 26.5%
Final simplification26.5%
(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 2023274
(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)))