
(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 (* (+ (* x -6.0) (* 6.0 y)) z)))
double code(double x, double y, double z) {
return x + (((x * -6.0) + (6.0 * y)) * 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 + (((x * (-6.0d0)) + (6.0d0 * y)) * z)
end function
public static double code(double x, double y, double z) {
return x + (((x * -6.0) + (6.0 * y)) * z);
}
def code(x, y, z): return x + (((x * -6.0) + (6.0 * y)) * z)
function code(x, y, z) return Float64(x + Float64(Float64(Float64(x * -6.0) + Float64(6.0 * y)) * z)) end
function tmp = code(x, y, z) tmp = x + (((x * -6.0) + (6.0 * y)) * z); end
code[x_, y_, z_] := N[(x + N[(N[(N[(x * -6.0), $MachinePrecision] + N[(6.0 * y), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x \cdot -6 + 6 \cdot y\right) \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e+22) (not (<= x 3e-73))) (+ x (* x (* -6.0 z))) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e+22) || !(x <= 3e-73)) {
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 <= (-1.55d+22)) .or. (.not. (x <= 3d-73))) 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 <= -1.55e+22) || !(x <= 3e-73)) {
tmp = x + (x * (-6.0 * z));
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e+22) or not (x <= 3e-73): 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 <= -1.55e+22) || !(x <= 3e-73)) tmp = Float64(x + Float64(x * Float64(-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 <= -1.55e+22) || ~((x <= 3e-73))) 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, -1.55e+22], N[Not[LessEqual[x, 3e-73]], $MachinePrecision]], N[(x + N[(x * N[(-6.0 * 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 -1.55 \cdot 10^{+22} \lor \neg \left(x \leq 3 \cdot 10^{-73}\right):\\
\;\;\;\;x + x \cdot \left(-6 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if x < -1.5500000000000001e22 or 3e-73 < x Initial program 99.9%
Taylor expanded in y around 0 84.0%
*-commutative84.0%
associate-*r*84.0%
*-commutative84.0%
Simplified84.0%
if -1.5500000000000001e22 < x < 3e-73Initial program 99.7%
Taylor expanded in y around inf 93.7%
*-commutative93.7%
Simplified93.7%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e+22) (not (<= x 3e-73))) (+ x (* -6.0 (* x z))) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e+22) || !(x <= 3e-73)) {
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.3d+22)) .or. (.not. (x <= 3d-73))) 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.3e+22) || !(x <= 3e-73)) {
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.3e+22) or not (x <= 3e-73): 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.3e+22) || !(x <= 3e-73)) 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.3e+22) || ~((x <= 3e-73))) 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.3e+22], N[Not[LessEqual[x, 3e-73]], $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.3 \cdot 10^{+22} \lor \neg \left(x \leq 3 \cdot 10^{-73}\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.2999999999999998e22 or 3e-73 < x Initial program 99.9%
Taylor expanded in y around 0 84.0%
if -3.2999999999999998e22 < x < 3e-73Initial program 99.7%
Taylor expanded in y around inf 93.7%
*-commutative93.7%
Simplified93.7%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.5e+22) (+ x (* (* x -6.0) z)) (if (<= x 3e-73) (+ x (* 6.0 (* y z))) (+ x (* x (* -6.0 z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+22) {
tmp = x + ((x * -6.0) * z);
} else if (x <= 3e-73) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (x * (-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.5d+22)) then
tmp = x + ((x * (-6.0d0)) * z)
else if (x <= 3d-73) then
tmp = x + (6.0d0 * (y * z))
else
tmp = x + (x * ((-6.0d0) * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+22) {
tmp = x + ((x * -6.0) * z);
} else if (x <= 3e-73) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (x * (-6.0 * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.5e+22: tmp = x + ((x * -6.0) * z) elif x <= 3e-73: tmp = x + (6.0 * (y * z)) else: tmp = x + (x * (-6.0 * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.5e+22) tmp = Float64(x + Float64(Float64(x * -6.0) * z)); elseif (x <= 3e-73) tmp = Float64(x + Float64(6.0 * Float64(y * z))); else tmp = Float64(x + Float64(x * Float64(-6.0 * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.5e+22) tmp = x + ((x * -6.0) * z); elseif (x <= 3e-73) tmp = x + (6.0 * (y * z)); else tmp = x + (x * (-6.0 * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.5e+22], N[(x + N[(N[(x * -6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3e-73], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(-6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+22}:\\
\;\;\;\;x + \left(x \cdot -6\right) \cdot z\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-73}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \left(-6 \cdot z\right)\\
\end{array}
\end{array}
if x < -1.5e22Initial program 100.0%
Taylor expanded in y around 0 85.6%
associate-*r*85.7%
Simplified85.7%
if -1.5e22 < x < 3e-73Initial program 99.7%
Taylor expanded in y around inf 93.7%
*-commutative93.7%
Simplified93.7%
if 3e-73 < x Initial program 99.8%
Taylor expanded in y around 0 82.3%
*-commutative82.3%
associate-*r*82.4%
*-commutative82.4%
Simplified82.4%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= y -4.05e+127) (* 6.0 (* y z)) (if (<= y 1.5e+46) (+ x (* -6.0 (* x z))) (* y (* 6.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.05e+127) {
tmp = 6.0 * (y * z);
} else if (y <= 1.5e+46) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = 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 (y <= (-4.05d+127)) then
tmp = 6.0d0 * (y * z)
else if (y <= 1.5d+46) then
tmp = x + ((-6.0d0) * (x * z))
else
tmp = y * (6.0d0 * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.05e+127) {
tmp = 6.0 * (y * z);
} else if (y <= 1.5e+46) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = y * (6.0 * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.05e+127: tmp = 6.0 * (y * z) elif y <= 1.5e+46: tmp = x + (-6.0 * (x * z)) else: tmp = y * (6.0 * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.05e+127) tmp = Float64(6.0 * Float64(y * z)); elseif (y <= 1.5e+46) tmp = Float64(x + Float64(-6.0 * Float64(x * z))); else tmp = Float64(y * Float64(6.0 * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.05e+127) tmp = 6.0 * (y * z); elseif (y <= 1.5e+46) tmp = x + (-6.0 * (x * z)); else tmp = y * (6.0 * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.05e+127], N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.5e+46], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.05 \cdot 10^{+127}:\\
\;\;\;\;6 \cdot \left(y \cdot z\right)\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+46}:\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(6 \cdot z\right)\\
\end{array}
\end{array}
if y < -4.0499999999999998e127Initial program 99.8%
Taylor expanded in y around inf 94.9%
*-commutative94.9%
Simplified94.9%
Taylor expanded in y around inf 94.8%
fma-define94.8%
Simplified94.8%
Taylor expanded in y around inf 79.4%
if -4.0499999999999998e127 < y < 1.50000000000000012e46Initial program 99.8%
Taylor expanded in y around 0 82.0%
if 1.50000000000000012e46 < y Initial program 99.8%
Taylor expanded in y around inf 87.8%
*-commutative87.8%
Simplified87.8%
Taylor expanded in y around inf 87.8%
fma-define87.8%
Simplified87.8%
Taylor expanded in y around inf 71.7%
associate-*r*71.8%
*-commutative71.8%
associate-*r*71.8%
Simplified71.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-9) (not (<= z 8.8e-60))) (* 6.0 (* y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-9) || !(z <= 8.8e-60)) {
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 <= (-3.5d-9)) .or. (.not. (z <= 8.8d-60))) 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 <= -3.5e-9) || !(z <= 8.8e-60)) {
tmp = 6.0 * (y * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e-9) or not (z <= 8.8e-60): tmp = 6.0 * (y * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-9) || !(z <= 8.8e-60)) 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 <= -3.5e-9) || ~((z <= 8.8e-60))) tmp = 6.0 * (y * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e-9], N[Not[LessEqual[z, 8.8e-60]], $MachinePrecision]], N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-9} \lor \neg \left(z \leq 8.8 \cdot 10^{-60}\right):\\
\;\;\;\;6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.4999999999999999e-9 or 8.7999999999999995e-60 < z Initial program 99.8%
Taylor expanded in y around inf 54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in y around inf 56.9%
fma-define57.0%
Simplified57.0%
Taylor expanded in y around inf 53.1%
if -3.4999999999999999e-9 < z < 8.7999999999999995e-60Initial program 99.9%
Taylor expanded in z around 0 77.8%
Final simplification62.9%
(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)
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.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 2024160
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
:precision binary64
:alt
(! :herbie-platform default (- x (* (* 6 z) (- x y))))
(+ x (* (* (- y x) 6.0) z)))