
(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 8 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 (* (* (- 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -8.2e+96)
(and (not (<= y -4.8e+57))
(or (<= y -2.4e-57) (not (<= y 2.05e-18)))))
(+ x (* 6.0 (* y z)))
(* x (+ 1.0 (* z -6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.2e+96) || (!(y <= -4.8e+57) && ((y <= -2.4e-57) || !(y <= 2.05e-18)))) {
tmp = x + (6.0 * (y * z));
} 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 <= (-8.2d+96)) .or. (.not. (y <= (-4.8d+57))) .and. (y <= (-2.4d-57)) .or. (.not. (y <= 2.05d-18))) then
tmp = x + (6.0d0 * (y * z))
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 <= -8.2e+96) || (!(y <= -4.8e+57) && ((y <= -2.4e-57) || !(y <= 2.05e-18)))) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x * (1.0 + (z * -6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.2e+96) or (not (y <= -4.8e+57) and ((y <= -2.4e-57) or not (y <= 2.05e-18))): tmp = x + (6.0 * (y * z)) else: tmp = x * (1.0 + (z * -6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.2e+96) || (!(y <= -4.8e+57) && ((y <= -2.4e-57) || !(y <= 2.05e-18)))) tmp = Float64(x + Float64(6.0 * Float64(y * z))); 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 <= -8.2e+96) || (~((y <= -4.8e+57)) && ((y <= -2.4e-57) || ~((y <= 2.05e-18))))) tmp = x + (6.0 * (y * z)); else tmp = x * (1.0 + (z * -6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.2e+96], And[N[Not[LessEqual[y, -4.8e+57]], $MachinePrecision], Or[LessEqual[y, -2.4e-57], N[Not[LessEqual[y, 2.05e-18]], $MachinePrecision]]]], N[(x + N[(6.0 * N[(y * z), $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 -8.2 \cdot 10^{+96} \lor \neg \left(y \leq -4.8 \cdot 10^{+57}\right) \land \left(y \leq -2.4 \cdot 10^{-57} \lor \neg \left(y \leq 2.05 \cdot 10^{-18}\right)\right):\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + z \cdot -6\right)\\
\end{array}
\end{array}
if y < -8.19999999999999996e96 or -4.80000000000000009e57 < y < -2.40000000000000006e-57 or 2.0499999999999999e-18 < y Initial program 99.9%
Taylor expanded in y around inf 93.4%
*-commutative93.4%
Simplified93.4%
if -8.19999999999999996e96 < y < -4.80000000000000009e57 or -2.40000000000000006e-57 < y < 2.0499999999999999e-18Initial program 99.8%
Taylor expanded in x around inf 88.3%
Final simplification91.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ 1.0 (* z -6.0)))) (t_1 (+ x (* z (* y 6.0)))))
(if (<= y -8.2e+96)
t_1
(if (<= y -6.2e+62)
t_0
(if (<= y -3.4e-57)
(+ x (* 6.0 (* y z)))
(if (<= y 1.36e-21) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 + (z * -6.0));
double t_1 = x + (z * (y * 6.0));
double tmp;
if (y <= -8.2e+96) {
tmp = t_1;
} else if (y <= -6.2e+62) {
tmp = t_0;
} else if (y <= -3.4e-57) {
tmp = x + (6.0 * (y * z));
} else if (y <= 1.36e-21) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = x * (1.0d0 + (z * (-6.0d0)))
t_1 = x + (z * (y * 6.0d0))
if (y <= (-8.2d+96)) then
tmp = t_1
else if (y <= (-6.2d+62)) then
tmp = t_0
else if (y <= (-3.4d-57)) then
tmp = x + (6.0d0 * (y * z))
else if (y <= 1.36d-21) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 + (z * -6.0));
double t_1 = x + (z * (y * 6.0));
double tmp;
if (y <= -8.2e+96) {
tmp = t_1;
} else if (y <= -6.2e+62) {
tmp = t_0;
} else if (y <= -3.4e-57) {
tmp = x + (6.0 * (y * z));
} else if (y <= 1.36e-21) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 + (z * -6.0)) t_1 = x + (z * (y * 6.0)) tmp = 0 if y <= -8.2e+96: tmp = t_1 elif y <= -6.2e+62: tmp = t_0 elif y <= -3.4e-57: tmp = x + (6.0 * (y * z)) elif y <= 1.36e-21: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 + Float64(z * -6.0))) t_1 = Float64(x + Float64(z * Float64(y * 6.0))) tmp = 0.0 if (y <= -8.2e+96) tmp = t_1; elseif (y <= -6.2e+62) tmp = t_0; elseif (y <= -3.4e-57) tmp = Float64(x + Float64(6.0 * Float64(y * z))); elseif (y <= 1.36e-21) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 + (z * -6.0)); t_1 = x + (z * (y * 6.0)); tmp = 0.0; if (y <= -8.2e+96) tmp = t_1; elseif (y <= -6.2e+62) tmp = t_0; elseif (y <= -3.4e-57) tmp = x + (6.0 * (y * z)); elseif (y <= 1.36e-21) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 + N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.2e+96], t$95$1, If[LessEqual[y, -6.2e+62], t$95$0, If[LessEqual[y, -3.4e-57], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.36e-21], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 + z \cdot -6\right)\\
t_1 := x + z \cdot \left(y \cdot 6\right)\\
\mathbf{if}\;y \leq -8.2 \cdot 10^{+96}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.4 \cdot 10^{-57}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{-21}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.19999999999999996e96 or 1.3599999999999999e-21 < y Initial program 99.9%
Taylor expanded in y around inf 95.2%
if -8.19999999999999996e96 < y < -6.20000000000000029e62 or -3.40000000000000016e-57 < y < 1.3599999999999999e-21Initial program 99.8%
Taylor expanded in x around inf 88.3%
if -6.20000000000000029e62 < y < -3.40000000000000016e-57Initial program 99.8%
Taylor expanded in y around inf 86.0%
*-commutative86.0%
Simplified86.0%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.17) (not (<= z 0.165))) (* -6.0 (* x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.17) || !(z <= 0.165)) {
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 <= 0.165d0))) 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 <= 0.165)) {
tmp = -6.0 * (x * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.17) or not (z <= 0.165): tmp = -6.0 * (x * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.17) || !(z <= 0.165)) 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 <= 0.165))) 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, 0.165]], $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 0.165\right):\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.170000000000000012 or 0.165000000000000008 < z Initial program 99.7%
Taylor expanded in x around 0 90.1%
Taylor expanded in z around inf 89.6%
*-commutative89.6%
Simplified89.6%
Taylor expanded in y around 0 50.7%
if -0.170000000000000012 < z < 0.165000000000000008Initial program 99.9%
Taylor expanded in z around 0 66.6%
Final simplification59.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.17) (* x (* z -6.0)) (if (<= z 0.165) x (* -6.0 (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.17) {
tmp = x * (z * -6.0);
} else if (z <= 0.165) {
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 <= (-0.17d0)) then
tmp = x * (z * (-6.0d0))
else if (z <= 0.165d0) 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 <= -0.17) {
tmp = x * (z * -6.0);
} else if (z <= 0.165) {
tmp = x;
} else {
tmp = -6.0 * (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.17: tmp = x * (z * -6.0) elif z <= 0.165: tmp = x else: tmp = -6.0 * (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.17) tmp = Float64(x * Float64(z * -6.0)); elseif (z <= 0.165) 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 <= -0.17) tmp = x * (z * -6.0); elseif (z <= 0.165) tmp = x; else tmp = -6.0 * (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.17], N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.165], x, N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17:\\
\;\;\;\;x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;z \leq 0.165:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if z < -0.170000000000000012Initial program 99.7%
Taylor expanded in x around inf 55.8%
Taylor expanded in z around inf 55.8%
*-commutative94.5%
Simplified55.8%
if -0.170000000000000012 < z < 0.165000000000000008Initial program 99.9%
Taylor expanded in z around 0 66.6%
if 0.165000000000000008 < z Initial program 99.8%
Taylor expanded in x around 0 85.5%
Taylor expanded in z around inf 84.5%
*-commutative84.5%
Simplified84.5%
Taylor expanded in y around 0 45.4%
Final simplification59.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.17) (* x (* z -6.0)) (if (<= z 0.165) x (* z (* x -6.0)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.17) {
tmp = x * (z * -6.0);
} else if (z <= 0.165) {
tmp = x;
} else {
tmp = 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 (z <= (-0.17d0)) then
tmp = x * (z * (-6.0d0))
else if (z <= 0.165d0) then
tmp = x
else
tmp = z * (x * (-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 = x * (z * -6.0);
} else if (z <= 0.165) {
tmp = x;
} else {
tmp = z * (x * -6.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.17: tmp = x * (z * -6.0) elif z <= 0.165: tmp = x else: tmp = z * (x * -6.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.17) tmp = Float64(x * Float64(z * -6.0)); elseif (z <= 0.165) tmp = x; else tmp = Float64(z * Float64(x * -6.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.17) tmp = x * (z * -6.0); elseif (z <= 0.165) tmp = x; else tmp = z * (x * -6.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.17], N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.165], x, N[(z * N[(x * -6.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17:\\
\;\;\;\;x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;z \leq 0.165:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot -6\right)\\
\end{array}
\end{array}
if z < -0.170000000000000012Initial program 99.7%
Taylor expanded in x around inf 55.8%
Taylor expanded in z around inf 55.8%
*-commutative94.5%
Simplified55.8%
if -0.170000000000000012 < z < 0.165000000000000008Initial program 99.9%
Taylor expanded in z around 0 66.6%
if 0.165000000000000008 < z Initial program 99.8%
Taylor expanded in x around 0 85.5%
Taylor expanded in z around inf 84.5%
*-commutative84.5%
Simplified84.5%
Taylor expanded in y around 0 45.4%
associate-*r*45.4%
*-commutative45.4%
*-commutative45.4%
Simplified45.4%
Final simplification59.5%
(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.9%
Taylor expanded in x around inf 60.9%
Final simplification60.9%
(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.9%
Taylor expanded in z around 0 38.3%
Final simplification38.3%
(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 2024045
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:alt
(- x (* (* 6.0 z) (- x y)))
(+ x (* (* (- y x) 6.0) z)))