
(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.8%
(FPCore (x y z)
:precision binary64
(if (<= y -1.06e+57)
(* 6.0 (* y z))
(if (or (<= y -2.2e+34) (and (not (<= y -5.8e-78)) (<= y 3.1e+65)))
(* x (+ (* z -6.0) 1.0))
(* z (* y 6.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e+57) {
tmp = 6.0 * (y * z);
} else if ((y <= -2.2e+34) || (!(y <= -5.8e-78) && (y <= 3.1e+65))) {
tmp = x * ((z * -6.0) + 1.0);
} else {
tmp = 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 (y <= (-1.06d+57)) then
tmp = 6.0d0 * (y * z)
else if ((y <= (-2.2d+34)) .or. (.not. (y <= (-5.8d-78))) .and. (y <= 3.1d+65)) then
tmp = x * ((z * (-6.0d0)) + 1.0d0)
else
tmp = z * (y * 6.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e+57) {
tmp = 6.0 * (y * z);
} else if ((y <= -2.2e+34) || (!(y <= -5.8e-78) && (y <= 3.1e+65))) {
tmp = x * ((z * -6.0) + 1.0);
} else {
tmp = z * (y * 6.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.06e+57: tmp = 6.0 * (y * z) elif (y <= -2.2e+34) or (not (y <= -5.8e-78) and (y <= 3.1e+65)): tmp = x * ((z * -6.0) + 1.0) else: tmp = z * (y * 6.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.06e+57) tmp = Float64(6.0 * Float64(y * z)); elseif ((y <= -2.2e+34) || (!(y <= -5.8e-78) && (y <= 3.1e+65))) tmp = Float64(x * Float64(Float64(z * -6.0) + 1.0)); else tmp = Float64(z * Float64(y * 6.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.06e+57) tmp = 6.0 * (y * z); elseif ((y <= -2.2e+34) || (~((y <= -5.8e-78)) && (y <= 3.1e+65))) tmp = x * ((z * -6.0) + 1.0); else tmp = z * (y * 6.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.06e+57], N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -2.2e+34], And[N[Not[LessEqual[y, -5.8e-78]], $MachinePrecision], LessEqual[y, 3.1e+65]]], N[(x * N[(N[(z * -6.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{+57}:\\
\;\;\;\;6 \cdot \left(y \cdot z\right)\\
\mathbf{elif}\;y \leq -2.2 \cdot 10^{+34} \lor \neg \left(y \leq -5.8 \cdot 10^{-78}\right) \land y \leq 3.1 \cdot 10^{+65}:\\
\;\;\;\;x \cdot \left(z \cdot -6 + 1\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot 6\right)\\
\end{array}
\end{array}
if y < -1.06e57Initial program 99.9%
Taylor expanded in y around inf 93.1%
*-commutative93.1%
Simplified93.1%
Taylor expanded in x around inf 74.6%
+-commutative74.6%
associate-/l*74.7%
Simplified74.7%
Taylor expanded in x around 0 78.3%
if -1.06e57 < y < -2.2000000000000002e34 or -5.8000000000000001e-78 < y < 3.09999999999999991e65Initial program 99.8%
Taylor expanded in x around inf 85.2%
+-commutative85.2%
Simplified85.2%
if -2.2000000000000002e34 < y < -5.8000000000000001e-78 or 3.09999999999999991e65 < y Initial program 99.7%
Taylor expanded in y around inf 88.1%
*-commutative88.1%
Simplified88.1%
Taylor expanded in x around inf 70.5%
+-commutative70.5%
associate-/l*68.1%
Simplified68.1%
Taylor expanded in x around 0 74.8%
associate-*r*74.9%
*-commutative74.9%
Simplified74.9%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.2e+100) (not (<= x 1.7e+148))) (* x (+ (* z -6.0) 1.0)) (+ x (* z (* y 6.0)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e+100) || !(x <= 1.7e+148)) {
tmp = x * ((z * -6.0) + 1.0);
} 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 <= (-5.2d+100)) .or. (.not. (x <= 1.7d+148))) then
tmp = x * ((z * (-6.0d0)) + 1.0d0)
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 <= -5.2e+100) || !(x <= 1.7e+148)) {
tmp = x * ((z * -6.0) + 1.0);
} else {
tmp = x + (z * (y * 6.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.2e+100) or not (x <= 1.7e+148): tmp = x * ((z * -6.0) + 1.0) else: tmp = x + (z * (y * 6.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.2e+100) || !(x <= 1.7e+148)) tmp = Float64(x * Float64(Float64(z * -6.0) + 1.0)); 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 <= -5.2e+100) || ~((x <= 1.7e+148))) tmp = x * ((z * -6.0) + 1.0); else tmp = x + (z * (y * 6.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.2e+100], N[Not[LessEqual[x, 1.7e+148]], $MachinePrecision]], N[(x * N[(N[(z * -6.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+100} \lor \neg \left(x \leq 1.7 \cdot 10^{+148}\right):\\
\;\;\;\;x \cdot \left(z \cdot -6 + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(y \cdot 6\right)\\
\end{array}
\end{array}
if x < -5.2000000000000003e100 or 1.7000000000000001e148 < x Initial program 99.9%
Taylor expanded in x around inf 92.6%
+-commutative92.6%
Simplified92.6%
if -5.2000000000000003e100 < x < 1.7000000000000001e148Initial program 99.8%
Taylor expanded in y around inf 89.4%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.06e+101) (not (<= x 2.8e+148))) (* x (+ (* z -6.0) 1.0)) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.06e+101) || !(x <= 2.8e+148)) {
tmp = x * ((z * -6.0) + 1.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 <= (-2.06d+101)) .or. (.not. (x <= 2.8d+148))) then
tmp = x * ((z * (-6.0d0)) + 1.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 <= -2.06e+101) || !(x <= 2.8e+148)) {
tmp = x * ((z * -6.0) + 1.0);
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.06e+101) or not (x <= 2.8e+148): tmp = x * ((z * -6.0) + 1.0) else: tmp = x + (6.0 * (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.06e+101) || !(x <= 2.8e+148)) tmp = Float64(x * Float64(Float64(z * -6.0) + 1.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 <= -2.06e+101) || ~((x <= 2.8e+148))) tmp = x * ((z * -6.0) + 1.0); else tmp = x + (6.0 * (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.06e+101], N[Not[LessEqual[x, 2.8e+148]], $MachinePrecision]], N[(x * N[(N[(z * -6.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.06 \cdot 10^{+101} \lor \neg \left(x \leq 2.8 \cdot 10^{+148}\right):\\
\;\;\;\;x \cdot \left(z \cdot -6 + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < -2.05999999999999993e101 or 2.7999999999999998e148 < x Initial program 99.9%
Taylor expanded in x around inf 92.6%
+-commutative92.6%
Simplified92.6%
if -2.05999999999999993e101 < x < 2.7999999999999998e148Initial program 99.8%
Taylor expanded in y around inf 89.4%
*-commutative89.4%
Simplified89.4%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -4e-34) (not (<= z 1.58e-58))) (* z (* y 6.0)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e-34) || !(z <= 1.58e-58)) {
tmp = z * (y * 6.0);
} 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 <= (-4d-34)) .or. (.not. (z <= 1.58d-58))) then
tmp = z * (y * 6.0d0)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4e-34) || !(z <= 1.58e-58)) {
tmp = z * (y * 6.0);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e-34) or not (z <= 1.58e-58): tmp = z * (y * 6.0) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4e-34) || !(z <= 1.58e-58)) tmp = Float64(z * Float64(y * 6.0)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4e-34) || ~((z <= 1.58e-58))) tmp = z * (y * 6.0); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4e-34], N[Not[LessEqual[z, 1.58e-58]], $MachinePrecision]], N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{-34} \lor \neg \left(z \leq 1.58 \cdot 10^{-58}\right):\\
\;\;\;\;z \cdot \left(y \cdot 6\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.99999999999999971e-34 or 1.57999999999999997e-58 < z Initial program 99.7%
Taylor expanded in y around inf 66.2%
*-commutative66.2%
Simplified66.2%
Taylor expanded in x around inf 49.5%
+-commutative49.5%
associate-/l*46.4%
Simplified46.4%
Taylor expanded in x around 0 62.7%
associate-*r*62.7%
*-commutative62.7%
Simplified62.7%
if -3.99999999999999971e-34 < z < 1.57999999999999997e-58Initial program 99.9%
Taylor expanded in z around 0 76.3%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.95e-33) (not (<= z 1.46e-61))) (* 6.0 (* y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.95e-33) || !(z <= 1.46e-61)) {
tmp = 6.0 * (y * 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 <= (-2.95d-33)) .or. (.not. (z <= 1.46d-61))) then
tmp = 6.0d0 * (y * z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.95e-33) || !(z <= 1.46e-61)) {
tmp = 6.0 * (y * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.95e-33) or not (z <= 1.46e-61): tmp = 6.0 * (y * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.95e-33) || !(z <= 1.46e-61)) tmp = Float64(6.0 * Float64(y * z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.95e-33) || ~((z <= 1.46e-61))) tmp = 6.0 * (y * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.95e-33], N[Not[LessEqual[z, 1.46e-61]], $MachinePrecision]], N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.95 \cdot 10^{-33} \lor \neg \left(z \leq 1.46 \cdot 10^{-61}\right):\\
\;\;\;\;6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.94999999999999993e-33 or 1.46e-61 < z Initial program 99.7%
Taylor expanded in y around inf 66.2%
*-commutative66.2%
Simplified66.2%
Taylor expanded in x around inf 49.5%
+-commutative49.5%
associate-/l*46.4%
Simplified46.4%
Taylor expanded in x around 0 62.7%
if -2.94999999999999993e-33 < z < 1.46e-61Initial program 99.9%
Taylor expanded in z around 0 76.3%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.165) (not (<= z 0.166))) (* -6.0 (* x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.165) || !(z <= 0.166)) {
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.165d0)) .or. (.not. (z <= 0.166d0))) 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.165) || !(z <= 0.166)) {
tmp = -6.0 * (x * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.165) or not (z <= 0.166): tmp = -6.0 * (x * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.165) || !(z <= 0.166)) 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.165) || ~((z <= 0.166))) tmp = -6.0 * (x * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.165], N[Not[LessEqual[z, 0.166]], $MachinePrecision]], N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.165 \lor \neg \left(z \leq 0.166\right):\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.165000000000000008 or 0.166000000000000009 < z Initial program 99.8%
Taylor expanded in y around 0 95.2%
fma-define95.2%
*-commutative95.2%
associate-*r*95.2%
Simplified95.2%
Taylor expanded in x around inf 43.5%
+-commutative43.5%
*-commutative43.5%
Simplified43.5%
Taylor expanded in z around inf 41.8%
Taylor expanded in x around 0 41.7%
if -0.165000000000000008 < z < 0.166000000000000009Initial program 99.9%
Taylor expanded in z around 0 66.5%
Final simplification53.5%
(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 33.2%
(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 2024091
(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)))