
(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 (fma (- y x) (* 6.0 z) x))
double code(double x, double y, double z) {
return fma((y - x), (6.0 * z), x);
}
function code(x, y, z) return fma(Float64(y - x), Float64(6.0 * z), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(6.0 * z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, 6 \cdot z, x\right)
\end{array}
Initial program 99.4%
+-commutative99.4%
associate-*l*99.8%
fma-define99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e+61) (not (<= x 2.8e+20))) (+ x (* -6.0 (* x z))) (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+61) || !(x <= 2.8e+20)) {
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 <= (-4d+61)) .or. (.not. (x <= 2.8d+20))) 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 <= -4e+61) || !(x <= 2.8e+20)) {
tmp = x + (-6.0 * (x * z));
} else {
tmp = x + (6.0 * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e+61) or not (x <= 2.8e+20): 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 <= -4e+61) || !(x <= 2.8e+20)) 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 <= -4e+61) || ~((x <= 2.8e+20))) 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, -4e+61], N[Not[LessEqual[x, 2.8e+20]], $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 -4 \cdot 10^{+61} \lor \neg \left(x \leq 2.8 \cdot 10^{+20}\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.9999999999999998e61 or 2.8e20 < x Initial program 98.9%
Taylor expanded in y around 0 91.9%
if -3.9999999999999998e61 < x < 2.8e20Initial program 99.8%
Taylor expanded in y around inf 89.3%
*-commutative89.3%
Simplified89.3%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (<= x -9.2e+61) (+ x (* x (* z -6.0))) (if (<= x 2.15e+18) (+ x (* 6.0 (* y z))) (+ x (* -6.0 (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.2e+61) {
tmp = x + (x * (z * -6.0));
} else if (x <= 2.15e+18) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (-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 (x <= (-9.2d+61)) then
tmp = x + (x * (z * (-6.0d0)))
else if (x <= 2.15d+18) then
tmp = x + (6.0d0 * (y * z))
else
tmp = x + ((-6.0d0) * (x * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -9.2e+61) {
tmp = x + (x * (z * -6.0));
} else if (x <= 2.15e+18) {
tmp = x + (6.0 * (y * z));
} else {
tmp = x + (-6.0 * (x * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.2e+61: tmp = x + (x * (z * -6.0)) elif x <= 2.15e+18: tmp = x + (6.0 * (y * z)) else: tmp = x + (-6.0 * (x * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.2e+61) tmp = Float64(x + Float64(x * Float64(z * -6.0))); elseif (x <= 2.15e+18) tmp = Float64(x + Float64(6.0 * Float64(y * z))); else tmp = Float64(x + Float64(-6.0 * Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.2e+61) tmp = x + (x * (z * -6.0)); elseif (x <= 2.15e+18) tmp = x + (6.0 * (y * z)); else tmp = x + (-6.0 * (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.2e+61], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.15e+18], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{+61}:\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{+18}:\\
\;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if x < -9.1999999999999998e61Initial program 99.9%
Taylor expanded in y around 0 92.5%
*-commutative92.5%
associate-*r*92.7%
*-commutative92.7%
Simplified92.7%
if -9.1999999999999998e61 < x < 2.15e18Initial program 99.8%
Taylor expanded in y around inf 89.3%
*-commutative89.3%
Simplified89.3%
if 2.15e18 < x Initial program 98.1%
Taylor expanded in y around 0 91.3%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e+61) (+ x (* x (* z -6.0))) (if (<= x 2.3e+51) (+ x (* y (* 6.0 z))) (+ x (* -6.0 (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+61) {
tmp = x + (x * (z * -6.0));
} else if (x <= 2.3e+51) {
tmp = x + (y * (6.0 * z));
} else {
tmp = x + (-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 (x <= (-7.2d+61)) then
tmp = x + (x * (z * (-6.0d0)))
else if (x <= 2.3d+51) then
tmp = x + (y * (6.0d0 * z))
else
tmp = x + ((-6.0d0) * (x * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+61) {
tmp = x + (x * (z * -6.0));
} else if (x <= 2.3e+51) {
tmp = x + (y * (6.0 * z));
} else {
tmp = x + (-6.0 * (x * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e+61: tmp = x + (x * (z * -6.0)) elif x <= 2.3e+51: tmp = x + (y * (6.0 * z)) else: tmp = x + (-6.0 * (x * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e+61) tmp = Float64(x + Float64(x * Float64(z * -6.0))); elseif (x <= 2.3e+51) tmp = Float64(x + Float64(y * Float64(6.0 * z))); else tmp = Float64(x + Float64(-6.0 * Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.2e+61) tmp = x + (x * (z * -6.0)); elseif (x <= 2.3e+51) tmp = x + (y * (6.0 * z)); else tmp = x + (-6.0 * (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e+61], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.3e+51], N[(x + N[(y * N[(6.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+61}:\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+51}:\\
\;\;\;\;x + y \cdot \left(6 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if x < -7.20000000000000021e61Initial program 99.9%
Taylor expanded in y around 0 92.5%
*-commutative92.5%
associate-*r*92.7%
*-commutative92.7%
Simplified92.7%
if -7.20000000000000021e61 < x < 2.30000000000000005e51Initial program 99.8%
Taylor expanded in y around 0 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 88.9%
associate-*r*89.0%
*-commutative89.0%
associate-*r*88.9%
Simplified88.9%
if 2.30000000000000005e51 < x Initial program 98.0%
Taylor expanded in y around 0 92.7%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (<= x -3.6e+61) (+ x (* x (* z -6.0))) (if (<= x 2.5e+52) (+ x (* z (* y 6.0))) (+ x (* -6.0 (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e+61) {
tmp = x + (x * (z * -6.0));
} else if (x <= 2.5e+52) {
tmp = x + (z * (y * 6.0));
} else {
tmp = x + (-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 (x <= (-3.6d+61)) then
tmp = x + (x * (z * (-6.0d0)))
else if (x <= 2.5d+52) then
tmp = x + (z * (y * 6.0d0))
else
tmp = x + ((-6.0d0) * (x * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e+61) {
tmp = x + (x * (z * -6.0));
} else if (x <= 2.5e+52) {
tmp = x + (z * (y * 6.0));
} else {
tmp = x + (-6.0 * (x * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.6e+61: tmp = x + (x * (z * -6.0)) elif x <= 2.5e+52: tmp = x + (z * (y * 6.0)) else: tmp = x + (-6.0 * (x * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.6e+61) tmp = Float64(x + Float64(x * Float64(z * -6.0))); elseif (x <= 2.5e+52) tmp = Float64(x + Float64(z * Float64(y * 6.0))); else tmp = Float64(x + Float64(-6.0 * Float64(x * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.6e+61) tmp = x + (x * (z * -6.0)); elseif (x <= 2.5e+52) tmp = x + (z * (y * 6.0)); else tmp = x + (-6.0 * (x * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.6e+61], N[(x + N[(x * N[(z * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.5e+52], N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+61}:\\
\;\;\;\;x + x \cdot \left(z \cdot -6\right)\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+52}:\\
\;\;\;\;x + z \cdot \left(y \cdot 6\right)\\
\mathbf{else}:\\
\;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if x < -3.6000000000000001e61Initial program 99.9%
Taylor expanded in y around 0 92.5%
*-commutative92.5%
associate-*r*92.7%
*-commutative92.7%
Simplified92.7%
if -3.6000000000000001e61 < x < 2.5e52Initial program 99.8%
Taylor expanded in y around inf 89.0%
if 2.5e52 < x Initial program 98.0%
Taylor expanded in y around 0 92.7%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (+ x (* z (* (- y x) 6.0))))
double code(double x, double y, double z) {
return x + (z * ((y - x) * 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 + (z * ((y - x) * 6.0d0))
end function
public static double code(double x, double y, double z) {
return x + (z * ((y - x) * 6.0));
}
def code(x, y, z): return x + (z * ((y - x) * 6.0))
function code(x, y, z) return Float64(x + Float64(z * Float64(Float64(y - x) * 6.0))) end
function tmp = code(x, y, z) tmp = x + (z * ((y - x) * 6.0)); end
code[x_, y_, z_] := N[(x + N[(z * N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \left(\left(y - x\right) \cdot 6\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.8%
Simplified99.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.4%
Taylor expanded in y around 0 59.5%
Final simplification59.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.4%
Taylor expanded in z around 0 34.3%
Final simplification34.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 2024046
(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)))